class Ini

Initialization (INI) configuration parser that uses "October flavoured INI", with the following improvements:

  • Parsing supports infinite array nesting
  • Ability to render INI from a PHP array

Methods

array
parse(string $contents)

Parses supplied INI contents in to a PHP array.

array
parseFile(string $fileName)

Parses supplied INI file contents in to a PHP array.

array
expandProperty(array $array, string $key, mixed $value)

Expands a single array property from traditional INI syntax.

string
render(array $vars = [], int $level = 1)

Formats an INI file string from an array

string
parsePreProcess(string $contents)

This method converts key names traditionally invalid, "][", and replaces them with a valid character "|" so parse_ini_string can function correctly. It also forces arrays to have unique indexes so their integrity is maintained.

array
parsePostProcess(array $array)

This method takes the valid key name from pre processing and converts it back to a real PHP array. Eg:

  • name[validation|regex|message] Converts to:
  • name => [validation => [regex => [message]]]

string
renderProperties(array $vars = [])

Renders section properties.

array
flattenProperties(array $array, string $prepend = '')

Flatten a multi-dimensional associative array for traditional INI syntax.

string
evalValue(string $value)

Converts a PHP value to make it suitable for INI format.

bool
isFinalArray(array $array)

Checks if the array is the final node in a multidimensional array.

Details

at line 23
array parse(string $contents)

Parses supplied INI contents in to a PHP array.

Parameters

string $contents

INI contents to parse

Return Value

array

at line 37
array parseFile(string $fileName)

Parses supplied INI file contents in to a PHP array.

Parameters

string $fileName

file to read contents and parse

Return Value

array

at line 52
array expandProperty(array $array, string $key, mixed $value)

Expands a single array property from traditional INI syntax.

If no key is given to the method, the entire array will be replaced.

Parameters

array $array array
string $key key
mixed $value value

Return Value

array

at line 81
string render(array $vars = [], int $level = 1)

Formats an INI file string from an array

Parameters

array $vars

data to format

int $level

specifies the level of array value

Return Value

string

returns the INI file string

at line 117
protected string parsePreProcess(string $contents)

This method converts key names traditionally invalid, "][", and replaces them with a valid character "|" so parse_ini_string can function correctly. It also forces arrays to have unique indexes so their integrity is maintained.

Parameters

string $contents

INI contents to parse

Return Value

string

at line 165
protected array parsePostProcess(array $array)

This method takes the valid key name from pre processing and converts it back to a real PHP array. Eg:

  • name[validation|regex|message] Converts to:
  • name => [validation => [regex => [message]]]

Parameters

array $array array

Return Value

array

at line 185
protected string renderProperties(array $vars = [])

Renders section properties.

Parameters

array $vars vars

Return Value

string

at line 224
protected array flattenProperties(array $array, string $prepend = '')

Flatten a multi-dimensional associative array for traditional INI syntax.

Parameters

array $array array
string $prepend prepend

Return Value

array

at line 251
protected string evalValue(string $value)

Converts a PHP value to make it suitable for INI format.

Strings are escaped.

Parameters

string $value

Specifies the value to process

Return Value

string

Returns the processed value

at line 268
protected bool isFinalArray(array $array)

Checks if the array is the final node in a multidimensional array.

Checked supplied array is not associative and contains no array values.

Parameters

array $array array

Return Value

bool