Fr3nch13/CakePHP Utilities

IniConfig
in package
implements ConfigEngineInterface uses FileConfigTrait

Ini file configuration engine.

Since IniConfig uses parse_ini_file underneath, you should be aware that this class shares the same behavior, especially with regards to boolean and null values.

In addition to the native parse_ini_file features, IniConfig also allows you to create nested array structures through usage of . delimited names. This allows you to create nested arrays structures in an ini config file. For example:

db.password = secret would turn into ['db' => ['password' => 'secret']]

You can nest properties as deeply as needed using .'s. In addition to using . you can use standard ini section notation to create nested structures:

[section]
key = value

Once loaded into Configure, the above would be accessed using:

`Configure::read('section.key');

You can also use . separated values in section names to create more deeply nested structures.

IniConfig also manipulates how the special ini values of 'yes', 'no', 'on', 'off', 'null' are handled. These values will be converted to their boolean equivalents.

Tags
see
https://secure.php.net/parse_ini_file

Table of Contents

Interfaces

ConfigEngineInterface
An interface for creating objects compatible with Configure::load()

Properties

$_extension  : string
File extension.
$_path  : string
The path this engine finds files on.
$_section  : string|null
The section to read, if null all sections will be read.

Methods

__construct()  : mixed
Build and construct a new ini file parser. The parser can be used to read ini files that are on the filesystem.
dump()  : bool
Dumps the state of Configure data into an ini formatted string.
read()  : array<string|int, mixed>
Read an ini file and return the results as an array.
_getFilePath()  : string
Get file path
_parseNestedValues()  : array<string|int, mixed>
parses nested values out of keys.
_value()  : string
Converts a value into the ini equivalent

Properties

$_extension

File extension.

protected string $_extension = '.ini'

$_path

The path this engine finds files on.

protected string $_path = ''

$_section

The section to read, if null all sections will be read.

protected string|null $_section

Methods

__construct()

Build and construct a new ini file parser. The parser can be used to read ini files that are on the filesystem.

public __construct([string|null $path = null ][, string|null $section = null ]) : mixed
Parameters
$path : string|null = null

Path to load ini config files from. Defaults to CONFIG.

$section : string|null = null

Only get one section, leave null to parse and fetch all sections in the ini file.

dump()

Dumps the state of Configure data into an ini formatted string.

public dump(string $key, array<string|int, mixed> $data) : bool
Parameters
$key : string

The identifier to write to. If the key has a . it will be treated as a plugin prefix.

$data : array<string|int, mixed>

The data to convert to ini file.

Return values
bool

Success.

read()

Read an ini file and return the results as an array.

public read(string $key) : array<string|int, mixed>
Parameters
$key : string

The identifier to read from. If the key has a . it will be treated as a plugin prefix. The chosen file must be on the engine's path.

Tags
throws
CakeException

when files don't exist. Or when files contain '..' as this could lead to abusive reads.

Return values
array<string|int, mixed>

Parsed configuration values.

_getFilePath()

Get file path

protected _getFilePath(string $key[, bool $checkExists = false ]) : string
Parameters
$key : string

The identifier to write to. If the key has a . it will be treated as a plugin prefix.

$checkExists : bool = false

Whether to check if file exists. Defaults to false.

Tags
throws
CakeException

When files don't exist or when files contain '..' as this could lead to abusive reads.

Return values
string

Full file path

_parseNestedValues()

parses nested values out of keys.

protected _parseNestedValues(array<string|int, mixed> $values) : array<string|int, mixed>
Parameters
$values : array<string|int, mixed>

Values to be exploded.

Return values
array<string|int, mixed>

Array of values exploded

_value()

Converts a value into the ini equivalent

protected _value(mixed $value) : string
Parameters
$value : mixed

Value to export.

Return values
string

String value for ini file.


        
On this page

Search results