October\Rain\Parse\Ini

Overview

Ini (Initialization) configuration parser that uses "October-flavoured INI", with parsing that supports infinite array nesting and the ability to render INI syntax from a PHP array.


Public Methods

public parse()

public parse(string $contents): array 

parse supplied INI contents in to a PHP array.

public parseFile()

public parseFile(string $fileName): array 

parseFile supplied INI file contents in to a PHP array.

public render()

public render(array $vars = [], array $options = []): string 

render formats an INI formatted string from an array of data variables

Supported options:

  • exceptionOnInvalidKey: if an exception must be thrown on invalid key names.

Protected Methods

protected evalValue()

protected evalValue(string $value): string 

evalValue converts a PHP value to make it suitable for INI format. Strings are escaped.

protected expandProperty()

protected expandProperty(
    array &$array,
    string $key,
    mixed $value
): array 

expandProperty expands a single array property from traditional INI syntax. If no key is given to the method, the entire array will be replaced.

protected flattenProperties()

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

flattenProperties flattens a multi-dimensional associative array for traditional INI syntax.

protected isFinalArray()

protected isFinalArray(array $array): bool 

isFinalArray checks if the array is the final node in a multidimensional array. Checked supplied array is not associative and contains no array values.

protected parsePostProcess()

protected parsePostProcess(array $array): array 

parsePostProcess 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]]]

protected parsePreProcess()

protected parsePreProcess(string $contents): string 

parsePreProcess 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.

protected renderProperties()

protected renderProperties(array $vars = []): string 

renderProperties renders section properties.

protected validateKeyName()

protected validateKeyName($keyName): bool 

validateKeyName returns false if an invalid key name is found