October\Rain\Parse\Ini

Source: ~/vendor/october/rain/src/Parse/Ini.php

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

Public methods

public 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
  • string $key
  • mixed $value

public array parse(string $contents)

Parses supplied INI contents in to a PHP array.

Parameters
  • string $contents - INI contents to parse.

public array parseFile(string $fileName)

Parses supplied INI file contents in to a PHP array.

Parameters
  • string $fileName - File to read contents and parse.

public string render(array $vars=array(), 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.

Protected methods

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

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

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

Parameters
  • array $array
  • string $prepend

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

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

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.

protected string renderProperties(array $vars=array())

Renders section properties.

Parameters
  • array $vars