class Config extends Collection

Config file loader and writer

Traits

Php Config file loader and writer

Properties

protected array $data Collection items data from Collection
protected array $comments Config array comments from PhpConfigFile

Methods

__construct(string|null $fileName = 'config.php', CacheInterface|null $cache = null, string $dir)

Constructor

static Collection
create(array $data)

Create colleciton

static Collection
createFromFile(string $fileName, string|null $root = null, array|null $vars = null)

Create colection form json file

ArrayIterator
getIterator()

Return iterator

bool
has(string $key)

Return true if key exists in collection

bool
offsetExists(string $key)

Return true if key exists in collection

union(array $data)

Union arrays

replace(array $replacement)

Replace array

mixed
offsetGet(string $key)

Get item

void
offsetSet(string $key, mixed $value)

Set item

void
offsetUnset(string $key)

Remove item

remove(string $key)

Remove item

void
removeEmptyItems()

Remove empy items

integer
count()

Return collection items count.

void
setBooleanValue(string $path, integer|string $value)

Set bool value

void
setValue(string $path, mixed $value)

Set item value by path

void
merge(string $key, array $data, bool $recursive = false)

Merge collection items

void
mergeItems(array $data, bool $recursive = false)

Merge all collection items

Collection
set(string $key, mixed $value)

Set item value in collection

void
add(string $key, mixed $value)

Add item to collection

bool
push(string $key, mixed $value, string|null $subKey = null)

Push value to collection

bool
prepend(string $key, mixed $value, string|null $subKey = null)

Add value to begining of collection array

withData(array $data)

Set collection data

array
slice(array|string $keys)

Slice collecion by keys

array
toArray()

Return collection array

bool
isEmpty(string $key)

Return true if key exists and value not empty in collection

getCollection(string $key)

Get collection item

mixed
get(string $key, mixed $default = null)

Get value from collection

bool
getBool(string $key, bool|null $default = null)

Get boolean value

string|null
getString(string $key, string|null $default = null)

Get text value

int|null
getInt(string $key, int|null $default = null)

Get int value

float|null
getFloat(string $key, float|null $default = null)

Get float value

array
getArray(string $key, mixed $default = null)

Return array values

void
clear()

Clear collection data

Collection
copy()

Clone object

mixed
__get(string $key)

Get value

__set(string $key, mixed $value)

Set value

mixed
getByPath(string $path, mixed $default = null)

Get value by path

bool
addField(string $path, mixed $value)

Add value

array
getItems()

Get collection items

array|null
include(string $fileName)

Include config file

array|null
includePhpArray(string $fileName)

Include php array

void
setComment(string $comment, string $key)

Set array key comment

string
getCommentsText(string $key)

Get array imtem comment as text

string
exportArray(array $data, string $arrayKey, int $currentTab = 1, int $endTab = 1)

Export array as text

string
exportItem(string $key, mixed $value, int $maxTabs)

Export item as text

string
exportConfig(array $data)

Export config as text

bool
saveConfigFile(string $fileName, array $data)

Save config file

CacheInterface|null
getCache()

Get cache

void
setReadProtectedVars(array $keys)

Set read protecetd vars keys

void
setWriteProtectedVars(array $keys)

Set write protecetd vars keys

bool
hasReadAccess(string $key)

Return true if var is not read protected

bool
hasWriteAccess(string $key)

Return true if var is not write protected

string
getConfigFile()

Get config file name

void
reloadConfig(bool $useCache = false)

Reload config file

void
setConfigDir(string $dir)

Set config dir

static Collection
read(string $fileName, string $configDir)

Read config file

array
load(string $fileName, bool $useCache = true)

Load config file

bool
save(string|null $fileName = null, array|null $data = null)

Save config file

array
loadJsonConfigFile(string $fileName)

Load json config file

bool
hasConfigFile(string $fileName)

Check if file exist

Details

at line 67
__construct(string|null $fileName = 'config.php', CacheInterface|null $cache = null, string $dir)

Constructor

Parameters

string|null $fileName
CacheInterface|null $cache
string $dir

in Collection at line 45
static Collection create(array $data)

Create colleciton

Parameters

array $data

Return Value

Collection

in Collection at line 58
static Collection createFromFile(string $fileName, string|null $root = null, array|null $vars = null)

Create colection form json file

Parameters

string $fileName
string|null $root
array|null $vars

Return Value

Collection

in Collection at line 73
ArrayIterator getIterator()

Return iterator

Return Value

ArrayIterator

in Collection at line 84
bool has(string $key)

Return true if key exists in collection

Parameters

string $key

Return Value

bool

in Collection at line 95
bool offsetExists(string $key)

Return true if key exists in collection

Parameters

string $key

Return Value

bool

in Collection at line 106
Collection union(array $data)

Union arrays

Parameters

array $data

Return Value

Collection

in Collection at line 119
Collection replace(array $replacement)

Replace array

Parameters

array $replacement

Return Value

Collection

in Collection at line 132
mixed offsetGet(string $key)

Get item

Parameters

string $key

Return Value

mixed

in Collection at line 144
void offsetSet(string $key, mixed $value)

Set item

Parameters

string $key
mixed $value

Return Value

void

in Collection at line 155
void offsetUnset(string $key)

Remove item

Parameters

string $key

Return Value

void

in Collection at line 166
Collection remove(string $key)

Remove item

Parameters

string $key

Return Value

Collection

in Collection at line 178
void removeEmptyItems()

Remove empy items

Return Value

void

in Collection at line 190
integer count()

Return collection items count.

Return Value

integer

in Collection at line 202
void setBooleanValue(string $path, integer|string $value)

Set bool value

Parameters

string $path
integer|string $value

Return Value

void

in Collection at line 221
void setValue(string $path, mixed $value)

Set item value by path

Parameters

string $path
mixed $value

Return Value

void

in Collection at line 234
void merge(string $key, array $data, bool $recursive = false)

Merge collection items

Parameters

string $key
array $data
bool $recursive

Return Value

void

in Collection at line 249
void mergeItems(array $data, bool $recursive = false)

Merge all collection items

Parameters

array $data
bool $recursive

Return Value

void

in Collection at line 261
Collection set(string $key, mixed $value)

Set item value in collection

Parameters

string $key Key Name
mixed $value Value

Return Value

Collection

in Collection at line 275
void add(string $key, mixed $value)

Add item to collection

Parameters

string $key key name
mixed $value

Return Value

void

in Collection at line 292
bool push(string $key, mixed $value, string|null $subKey = null)

Push value to collection

Parameters

string $key
mixed $value
string|null $subKey

Return Value

bool

in Collection at line 319
bool prepend(string $key, mixed $value, string|null $subKey = null)

Add value to begining of collection array

Parameters

string $key
mixed $value
string|null $subKey

Return Value

bool

in Collection at line 343
Collection withData(array $data)

Set collection data

Parameters

array $data

Return Value

Collection

in Collection at line 356
array slice(array|string $keys)

Slice collecion by keys

Parameters

array|string $keys

Return Value

array

in Collection at line 366
array toArray()

Return collection array

Return Value

array

in Collection at line 377
bool isEmpty(string $key)

Return true if key exists and value not empty in collection

Parameters

string $key

Return Value

bool

in Collection at line 388
Collection getCollection(string $key)

Get collection item

Parameters

string $key

Return Value

Collection

in Collection at line 400
mixed get(string $key, mixed $default = null)

Get value from collection

Parameters

string $key Name
mixed $default If key not exists return default value

Return Value

mixed

in Collection at line 412
bool getBool(string $key, bool|null $default = null)

Get boolean value

Parameters

string $key
bool|null $default

Return Value

bool

in Collection at line 424
string|null getString(string $key, string|null $default = null)

Get text value

Parameters

string $key
string|null $default

Return Value

string|null

in Collection at line 438
int|null getInt(string $key, int|null $default = null)

Get int value

Parameters

string $key
int|null $default

Return Value

int|null

in Collection at line 452
float|null getFloat(string $key, float|null $default = null)

Get float value

Parameters

string $key
float|null $default

Return Value

float|null

in Collection at line 466
array getArray(string $key, mixed $default = null)

Return array values

Parameters

string $key
mixed $default

Return Value

array

in Collection at line 478
void clear()

Clear collection data

Return Value

void

in Collection at line 488
Collection copy()

Clone object

Return Value

Collection

in Collection at line 499
mixed __get(string $key)

Get value

Parameters

string $key

Return Value

mixed

in Collection at line 510
__set(string $key, mixed $value)

Set value

Parameters

string $key
mixed $value

in Collection at line 522
mixed getByPath(string $path, mixed $default = null)

Get value by path

Parameters

string $path
mixed $default

Return Value

mixed

in Collection at line 536
bool addField(string $path, mixed $value)

Add value

Parameters

string $path
mixed $value

Return Value

bool

in Collection at line 555
array getItems()

Get collection items

Return Value

array

in PhpConfigFile at line 33
array|null include(string $fileName)

Include config file

Parameters

string $fileName

Return Value

array|null

in PhpConfigFile at line 44
array|null includePhpArray(string $fileName)

Include php array

Parameters

string $fileName

Return Value

array|null

in PhpConfigFile at line 62
protected void setComment(string $comment, string $key)

Set array key comment

Parameters

string $comment
string $key

Return Value

void

in PhpConfigFile at line 73
protected string getCommentsText(string $key)

Get array imtem comment as text

Parameters

string $key

Return Value

string

in PhpConfigFile at line 100
protected string exportArray(array $data, string $arrayKey, int $currentTab = 1, int $endTab = 1)

Export array as text

Parameters

array $data
string $arrayKey
int $currentTab
int $endTab

Return Value

string

in PhpConfigFile at line 144
protected string exportItem(string $key, mixed $value, int $maxTabs)

Export item as text

Parameters

string $key
mixed $value
int $maxTabs

Return Value

string

in PhpConfigFile at line 158
protected string exportConfig(array $data)

Export config as text

Parameters

array $data

Return Value

string

in PhpConfigFile at line 245
bool saveConfigFile(string $fileName, array $data)

Save config file

Parameters

string $fileName
array $data

Return Value

bool

at line 85
CacheInterface|null getCache()

Get cache

Return Value

CacheInterface|null

at line 96
void setReadProtectedVars(array $keys)

Set read protecetd vars keys

Parameters

array $keys

Return Value

void

at line 107
void setWriteProtectedVars(array $keys)

Set write protecetd vars keys

Parameters

array $keys

Return Value

void

at line 118
bool hasReadAccess(string $key)

Return true if var is not read protected

Parameters

string $key

Return Value

bool

at line 129
bool hasWriteAccess(string $key)

Return true if var is not write protected

Parameters

string $key

Return Value

bool

at line 139
string getConfigFile()

Get config file name

Return Value

string

at line 150
void reloadConfig(bool $useCache = false)

Reload config file

Parameters

bool $useCache

Return Value

void

at line 166
void setConfigDir(string $dir)

Set config dir

Parameters

string $dir

Return Value

void

at line 178
static Collection read(string $fileName, string $configDir)

Read config file

Parameters

string $fileName
string $configDir

Return Value

Collection

at line 190
array load(string $fileName, bool $useCache = true)

Load config file

Parameters

string $fileName
bool $useCache

Return Value

array

at line 216
bool save(string|null $fileName = null, array|null $data = null)

Save config file

Parameters

string|null $fileName
array|null $data

Return Value

bool

at line 234
array loadJsonConfigFile(string $fileName)

Load json config file

Parameters

string $fileName

Return Value

array

at line 247
bool hasConfigFile(string $fileName)

Check if file exist

Parameters

string $fileName

Return Value

bool