Ini

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

 class Winter\Storm\Parse\Ini
  • Parsing supports infinite array nesting
  • Ability to render INI from a PHP array

Methods

public expandProperty (array $array, string | null $key = null, mixed $value = null) : array

Expands a single array property from traditional INI syntax.

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

Parameters
Property Description
$array
array
$key
string | null
$value
mixed
Returns
array

public parse (string $contents) : array

Parses supplied INI contents in to a PHP array.

Parameters
Property Description
$contents
string

INI contents to parse.

Returns
array

public parseFile (string $fileName) : array

Parses supplied INI file contents in to a PHP array.

Parameters
Property Description
$fileName
string

File to read contents and parse.

Returns
array

public render (array $vars = [], integer $level = 1) : string

Formats an INI file string from an array

Parameters
Property Description
$vars
array

Data to format.

$level
integer

Specifies the level of array value.

Returns
string

Returns the INI file string.

protected evalValue (string $value) : string

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

Strings are escaped.

Parameters
Property Description
$value
string

Specifies the value to process

Returns
string

Returns the processed value

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

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

Parameters
Property Description
$array
array
$prepend
string
Returns
array

protected isFinalArray (array $array) : bool

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

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

Parameters
Property Description
$array
array
Returns
bool

protected parsePostProcess (array $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
Property Description
$array
array
Returns
array

protected parsePreProcess (string $contents) : string

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
Property Description
$contents
string

INI contents to parse.

Returns
string

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

Renders section properties.

Parameters
Property Description
$vars
array
Returns
string
Copyright © 2024 Winter CMS