Config
in package
implements
IteratorAggregate
Class for working with YAML configuration files.
Table of Contents
Interfaces
- IteratorAggregate
Properties
- $_configData : mixed
- Holds the loaded configuration data.
- $_file : string
Methods
- __construct() : mixed
- Constructor.
- AsArray() : array<string|int, mixed>|null
- Return the internal data as an array.
- AsObject() : object|string|null
- Return the internal data as an object.
- Enumerate() : array<string|int, mixed>
- Retrieves all configuration files in the /config folder.
- GetFile() : string
- Get the file name.
- getIterator() : ArrayListIterator
- Get an iterator for the object.
- GetValue() : mixed
- Return the stored value.
- isKindOfObject() : bool
- Checks for the associativeness of the array.
- Item() : mixed
- Retrieve an item by index.
- Load() : Config
- Load YAML string.
- LoadFile() : Config
- Load a YAML file.
- Query() : ConfigItemsList|Config
- Retrieve a value from the configuration.
- Save() : bool
- Save the configuration to a YAML file.
- Set() : void
- Set a value.
- _prepareValue() : mixed
- Function for processing YAML commands.
Properties
$_configData
Holds the loaded configuration data.
private
mixed
$_configData
$_file
private
string
$_file
= ''
Methods
__construct()
Constructor.
public
__construct(mixed $fileName[, bool $isFile = true ][, string $file = '' ]) : mixed
Parameters
- $fileName : mixed
-
File or data
- $isFile : bool = true
-
Indicates whether a file was passed or a string
- $file : string = ''
AsArray()
Return the internal data as an array.
public
AsArray() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullAsObject()
Return the internal data as an object.
public
AsObject() : object|string|null
Return values
object|string|nullEnumerate()
Retrieves all configuration files in the /config folder.
public
static Enumerate() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of configuration files
GetFile()
Get the file name.
public
GetFile() : string
Return values
string —The file name
getIterator()
Get an iterator for the object.
public
getIterator() : ArrayListIterator
Return values
ArrayListIterator —An iterator for the object
GetValue()
Return the stored value.
public
GetValue() : mixed
Warning! If the current data is an array or object, null will be returned.
isKindOfObject()
Checks for the associativeness of the array.
public
isKindOfObject(array<string|int, mixed>|null $param) : bool
Parameters
- $param : array<string|int, mixed>|null
Return values
boolItem()
Retrieve an item by index.
public
Item(int $index) : mixed
Parameters
- $index : int
-
The index of the item
Return values
mixed —The item
Load()
Load YAML string.
public
static Load(string $yamlData) : Config
Parameters
- $yamlData : string
-
The YAML data
Return values
Config —A Config object representing the loaded YAML string
LoadFile()
Load a YAML file.
public
static LoadFile(string $fileName) : Config
Parameters
- $fileName : string
-
The name of the YAML file
Return values
Config —A Config object representing the loaded YAML file
Query()
Retrieve a value from the configuration.
public
Query(string|array<string|int, mixed> $item[, mixed $default = null ]) : ConfigItemsList|Config
Paths are specified in JavaScript notation. For example: settings.item[0].info or settings.item.buh.notice_email
Parameters
- $item : string|array<string|int, mixed>
-
The path to the value in the configuration file, if an array is passed, all elements will be sequentially requested until a positive response is found, if nothing is found, an attempt will be made to return $default
- $default : mixed = null
-
The default value if the path is not found
Return values
ConfigItemsList|ConfigSave()
Save the configuration to a YAML file.
public
Save([string $fileName = '' ]) : bool
Parameters
- $fileName : string = ''
-
The name of the YAML file
Tags
Return values
bool —True if the configuration was saved successfully, otherwise false
Set()
Set a value.
public
Set(string $item, mixed $value) : void
Parameters
- $item : string
-
The item name
- $value : mixed
-
The value
Tags
_prepareValue()
Function for processing YAML commands.
private
_prepareValue(mixed $value[, string $file = '' ]) : mixed
Parameters
- $value : mixed
-
The value
- $file : string = ''