Config
extends Collection
in package
Uses
PhpConfigFile
Config file loader and writer
Table of Contents
Properties
- $comments : array<string|int, mixed>
- Config array comments
- $data : array<string|int, mixed>
- Collection items data
- $configDir : string
- Config files directory
- $fileName : string
- Config file name
- $readProtectedKeys : array<string|int, mixed>
- List read protected var keys
- $writeProtectedKeys : array<string|int, mixed>
- List write protected var keys
Methods
- __construct() : mixed
- Constructor
- __get() : mixed
- Get value
- __set() : mixed
- Set value
- add() : void
- Add item to collection
- addField() : bool
- Add value
- clear() : void
- Clear collection data
- copy() : self
- Clone object
- count() : int
- Return collection items count.
- create() : Collection
- Create colleciton
- createFromFile() : Collection
- Create colection form json file
- get() : mixed
- Get value from collection
- getArray() : array<string|int, mixed>
- Return array values
- getBool() : bool
- Get boolean value
- getByPath() : mixed
- Get value by path
- getCollection() : Collection
- Get collection item
- getConfigFile() : string
- Get config file name
- getFloat() : float|null
- Get float value
- getInt() : int|null
- Get int value
- getItems() : array<string|int, mixed>
- Get collection items
- getIterator() : ArrayIterator
- Return iterator
- getString() : string
- Get text value
- has() : bool
- Return true if key exists in collection
- hasConfigFile() : bool
- Check if file exist
- hasReadAccess() : bool
- Return true if var is not read protected
- hasWriteAccess() : bool
- Return true if var is not write protected
- include() : array<string|int, mixed>|null
- Include file
- includeConfigFile() : array<string|int, mixed>|null
- Include config file
- includePhpArray() : array<string|int, mixed>|null
- Include php array
- isEmpty() : bool
- Return true if key exists and value not empty in collection
- load() : array<string|int, mixed>
- Load config file
- loadJsonConfigFile() : array<string|int, mixed>
- Load json config file
- merge() : void
- Merge collection items
- mergeItems() : void
- Merge all collection items
- offsetExists() : bool
- Return true if key exists in collection
- offsetGet() : mixed
- Get item
- offsetSet() : void
- Set item
- offsetUnset() : void
- Remove item
- prepend() : bool
- Add value to begining of collection array
- push() : bool
- Push value to collection
- read() : Collection
- Read config file
- reloadConfig() : void
- Reload config file
- remove() : Collection
- Remove item
- removeEmptyItems() : void
- Remove empy items
- replace() : Collection
- Replace array
- save() : bool
- Save config file
- saveConfigFile() : bool
- Save config file
- set() : Collection
- Set item value in collection
- setArrayValue() : array<string|int, mixed>
- Set array value
- setBooleanValue() : void
- Set bool value
- setConfigDir() : void
- Set config dir
- setReadProtectedVars() : void
- Set read protecetd vars keys
- setValue() : void
- Set item value by path
- setWriteProtectedVars() : void
- Set write protecetd vars keys
- slice() : array<string|int, mixed>
- Slice collecion by keys
- toArray() : array<string|int, mixed>
- Return collection array
- union() : Collection
- Union arrays
- withData() : Collection
- Set collection data
- exportArray() : string
- Export array as text
- exportConfig() : string
- Export config as text
- exportItem() : string
- Export item as text
- getCommentsText() : string
- Get array imtem comment as text
- setComment() : void
- Set array key comment
- determineMaxTabs() : int
- Get max tabs count
- determineTabs() : int
- Get tabs count for array key
- getFileContent() : string
- Return config file content
- getFileContentHeader() : string
- Get config file header
- getTabs() : string
- Get tabs text
Properties
$comments
Config array comments
protected
array<string|int, mixed>
$comments
= []
$data
Collection items data
protected
array<string|int, mixed>
$data
= []
$configDir
Config files directory
private
string
$configDir
$fileName
Config file name
private
string
$fileName
$readProtectedKeys
List read protected var keys
private
array<string|int, mixed>
$readProtectedKeys
= []
$writeProtectedKeys
List write protected var keys
private
array<string|int, mixed>
$writeProtectedKeys
= []
Methods
__construct()
Constructor
public
__construct([string|null $fileName = 'config.php' ][, string|null $path = null ]) : mixed
Parameters
- $fileName : string|null = 'config.php'
- $path : string|null = null
__get()
Get value
public
__get(string $key) : mixed
Parameters
- $key : string
__set()
Set value
public
__set(string $key, mixed $value) : mixed
Parameters
- $key : string
- $value : mixed
add()
Add item to collection
public
add(string $key, mixed $value) : void
Parameters
- $key : string
-
key name
- $value : mixed
addField()
Add value
public
addField(string $path, mixed $value) : bool
Parameters
- $path : string
- $value : mixed
Return values
boolclear()
Clear collection data
public
clear() : void
copy()
Clone object
public
copy() : self
Return values
selfcount()
Return collection items count.
public
count() : int
Return values
intcreate()
Create colleciton
public
static create(array<string|int, mixed> $data) : Collection
Parameters
- $data : array<string|int, mixed>
Return values
CollectioncreateFromFile()
Create colection form json file
public
static createFromFile(string $fileName[, string|null $root = null ][, array<string|int, mixed>|null $vars = null ]) : Collection
Parameters
- $fileName : string
- $root : string|null = null
- $vars : array<string|int, mixed>|null = null
Return values
Collectionget()
Get value from collection
public
get(string $key[, mixed $default = null ]) : mixed
Parameters
- $key : string
-
Name
- $default : mixed = null
-
If key not exists return default value
getArray()
Return array values
public
getArray(string $key[, mixed $default = null ]) : array<string|int, mixed>
Parameters
- $key : string
- $default : mixed = null
Return values
array<string|int, mixed>getBool()
Get boolean value
public
getBool(string $key[, bool|null $default = null ]) : bool
Parameters
- $key : string
- $default : bool|null = null
Return values
boolgetByPath()
Get value by path
public
getByPath(string $path[, mixed $default = null ]) : mixed
Parameters
- $path : string
- $default : mixed = null
getCollection()
Get collection item
public
getCollection(string $key) : Collection
Parameters
- $key : string
Return values
CollectiongetConfigFile()
Get config file name
public
getConfigFile() : string
Return values
stringgetFloat()
Get float value
public
getFloat(string $key[, float|null $default = null ]) : float|null
Parameters
- $key : string
- $default : float|null = null
Return values
float|nullgetInt()
Get int value
public
getInt(string $key[, int|null $default = null ]) : int|null
Parameters
- $key : string
- $default : int|null = null
Return values
int|nullgetItems()
Get collection items
public
getItems() : array<string|int, mixed>
Return values
array<string|int, mixed>getIterator()
Return iterator
public
getIterator() : ArrayIterator
Return values
ArrayIteratorgetString()
Get text value
public
getString(string $key[, string|null $default = null ]) : string
Parameters
- $key : string
- $default : string|null = null
Return values
stringhas()
Return true if key exists in collection
public
has(string $key) : bool
Parameters
- $key : string
Return values
boolhasConfigFile()
Check if file exist
public
hasConfigFile(string $fileName) : bool
Parameters
- $fileName : string
Return values
boolhasReadAccess()
Return true if var is not read protected
public
hasReadAccess(string $key) : bool
Parameters
- $key : string
Return values
boolhasWriteAccess()
Return true if var is not write protected
public
hasWriteAccess(string $key) : bool
Parameters
- $key : string
Return values
boolinclude()
Include file
public
include(string $fileName) : array<string|int, mixed>|null
Parameters
- $fileName : string
-
Full file name
Return values
array<string|int, mixed>|nullincludeConfigFile()
Include config file
public
includeConfigFile(string $fileName[, string|null $extensionName = null ]) : array<string|int, mixed>|null
Parameters
- $fileName : string
- $extensionName : string|null = null
Return values
array<string|int, mixed>|nullincludePhpArray()
Include php array
public
includePhpArray(string $fileName) : array<string|int, mixed>|null
Parameters
- $fileName : string
Return values
array<string|int, mixed>|nullisEmpty()
Return true if key exists and value not empty in collection
public
isEmpty(string $key) : bool
Parameters
- $key : string
-
Name
Return values
boolload()
Load config file
public
load(string $fileName) : array<string|int, mixed>
Parameters
- $fileName : string
Return values
array<string|int, mixed>loadJsonConfigFile()
Load json config file
public
loadJsonConfigFile(string $fileName) : array<string|int, mixed>
Parameters
- $fileName : string
Return values
array<string|int, mixed>merge()
Merge collection items
public
merge(string $key, array<string|int, mixed> $data[, bool $recursive = false ]) : void
Parameters
- $key : string
- $data : array<string|int, mixed>
- $recursive : bool = false
mergeItems()
Merge all collection items
public
mergeItems(array<string|int, mixed> $data[, bool $recursive = false ]) : void
Parameters
- $data : array<string|int, mixed>
- $recursive : bool = false
offsetExists()
Return true if key exists in collection
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
Return values
booloffsetGet()
Get item
public
offsetGet(mixed $offset) : mixed
Parameters
- $offset : mixed
offsetSet()
Set item
public
offsetSet(mixed $offset, mixed $value) : void
Parameters
- $offset : mixed
- $value : mixed
offsetUnset()
Remove item
public
offsetUnset(mixed $offset) : void
Parameters
- $offset : mixed
prepend()
Add value to begining of collection array
public
prepend(string $key, mixed $value[, string|null $subKey = null ]) : bool
Parameters
- $key : string
- $value : mixed
- $subKey : string|null = null
Return values
boolpush()
Push value to collection
public
push(string $key, mixed $value[, string|null $subKey = null ]) : bool
Parameters
- $key : string
- $value : mixed
- $subKey : string|null = null
Return values
boolread()
Read config file
public
static read(string $fileName, string $configDir) : Collection
Parameters
- $fileName : string
- $configDir : string
Return values
CollectionreloadConfig()
Reload config file
public
reloadConfig() : void
remove()
Remove item
public
remove(string $key) : Collection
Parameters
- $key : string
Return values
CollectionremoveEmptyItems()
Remove empy items
public
removeEmptyItems() : void
replace()
Replace array
public
replace(array<string|int, mixed> $replacement) : Collection
Parameters
- $replacement : array<string|int, mixed>
Return values
Collectionsave()
Save config file
public
save([string|null $fileName = null ][, array<string|int, mixed>|null $data = null ]) : bool
Parameters
- $fileName : string|null = null
- $data : array<string|int, mixed>|null = null
Return values
boolsaveConfigFile()
Save config file
public
saveConfigFile(string $fileName, array<string|int, mixed> $data) : bool
Parameters
- $fileName : string
- $data : array<string|int, mixed>
Return values
boolset()
Set item value in collection
public
set(string $key, mixed $value) : Collection
Parameters
- $key : string
-
Key Name
- $value : mixed
-
Value
Return values
CollectionsetArrayValue()
Set array value
public
static setArrayValue(array<string|int, mixed> $array, string $path, mixed $value[, string $separator = '/' ]) : array<string|int, mixed>
Parameters
- $array : array<string|int, mixed>
- $path : string
- $value : mixed
- $separator : string = '/'
Return values
array<string|int, mixed>setBooleanValue()
Set bool value
public
setBooleanValue(string $path, int|string $value) : void
Parameters
- $path : string
- $value : int|string
setConfigDir()
Set config dir
public
setConfigDir(string $dir) : void
Parameters
- $dir : string
setReadProtectedVars()
Set read protecetd vars keys
public
setReadProtectedVars(array<string|int, mixed> $keys) : void
Parameters
- $keys : array<string|int, mixed>
setValue()
Set item value by path
public
setValue(string $path, mixed $value) : void
Parameters
- $path : string
- $value : mixed
setWriteProtectedVars()
Set write protecetd vars keys
public
setWriteProtectedVars(array<string|int, mixed> $keys) : void
Parameters
- $keys : array<string|int, mixed>
slice()
Slice collecion by keys
public
slice(array<string|int, mixed>|string $keys) : array<string|int, mixed>
Parameters
- $keys : array<string|int, mixed>|string
Return values
array<string|int, mixed>toArray()
Return collection array
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>union()
Union arrays
public
union(array<string|int, mixed> $data) : Collection
Parameters
- $data : array<string|int, mixed>
Return values
CollectionwithData()
Set collection data
public
withData(array<string|int, mixed> $data) : Collection
Parameters
- $data : array<string|int, mixed>
Return values
CollectionexportArray()
Export array as text
protected
exportArray(array<string|int, mixed> $data, string $arrayKey[, int $currentTab = 1 ]) : string
Parameters
- $data : array<string|int, mixed>
- $arrayKey : string
- $currentTab : int = 1
Return values
stringexportConfig()
Export config as text
protected
exportConfig(array<string|int, mixed> $data) : string
Parameters
- $data : array<string|int, mixed>
Return values
stringexportItem()
Export item as text
protected
exportItem(string|int $key, mixed $value, int $maxTabs[, int $startTab = 1 ]) : string
Parameters
- $key : string|int
- $value : mixed
- $maxTabs : int
- $startTab : int = 1
Return values
stringgetCommentsText()
Get array imtem comment as text
protected
getCommentsText(string $key) : string
Parameters
- $key : string
Return values
stringsetComment()
Set array key comment
protected
setComment(string $comment, string $key) : void
Parameters
- $comment : string
- $key : string
determineMaxTabs()
Get max tabs count
private
determineMaxTabs(array<string|int, mixed> $data[, int $tabSize = 4 ]) : int
Parameters
- $data : array<string|int, mixed>
- $tabSize : int = 4
Return values
intdetermineTabs()
Get tabs count for array key
private
determineTabs(string $key[, int $tabSize = 4 ]) : int
Parameters
- $key : string
- $tabSize : int = 4
Return values
intgetFileContent()
Return config file content
private
getFileContent(array<string|int, mixed> $data) : string
Parameters
- $data : array<string|int, mixed>
Return values
stringgetFileContentHeader()
Get config file header
private
getFileContentHeader() : string
Return values
stringgetTabs()
Get tabs text
private
getTabs(int $count) : string
Parameters
- $count : int