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.
Property | Type | Description |
---|---|---|
$array | array |
array
|
$key | string | null |
string | null
|
$value | mixed |
mixed
|
public parse (string $contents) : array
Parses supplied INI contents in to a PHP array.
Property | Type | Description |
---|---|---|
$contents | string |
string
INI contents to parse. |
public parseFile (string $fileName) : array
Parses supplied INI file contents in to a PHP array.
Property | Type | Description |
---|---|---|
$fileName | string |
string
File to read contents and parse. |
public
render (array $vars = []
, integer $level = 1
)
: string
Formats an INI file string from an array
Property | Type | Description |
---|---|---|
$vars | array |
array
Data to format. |
$level | integer |
integer
Specifies the level of array value. |
Returns the INI file string.
protected evalValue (string $value) : string
Converts a PHP value to make it suitable for INI format.
Strings are escaped.
Property | Type | Description |
---|---|---|
$value | string |
string
Specifies the value to process |
Returns the processed value
protected
flattenProperties (array $array, string $prepend = ""
)
: array
Flatten a multi-dimensional associative array for traditional INI syntax.
Property | Type | Description |
---|---|---|
$array | array |
array
|
$prepend | string |
string
|
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.
Property | Type | Description |
---|---|---|
$array | array |
array
|
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]]]
Property | Type | Description |
---|---|---|
$array | array |
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.
Property | Type | Description |
---|---|---|
$contents | string |
string
INI contents to parse. |
protected
renderProperties (array $vars = []
)
: string
Renders section properties.
Property | Type | Description |
---|---|---|
$vars | array |
array
|