$sections
$sections : array
sections, holds the config sections
Config_Lite Class
read and save ini text files. Config_Lite has the native PHP function `parse_ini_file' under the hood. The API is inspired by Python's ConfigParser. A "Config_Lite" file consists of "name = value" entries and sections, "[section]" followed by "name = value" entries
read(string $filename = null, integer $mode = INI_SCANNER_NORMAL) : \Config_Lite
the read method parses the optional given filename or already setted filename.
this method uses the native PHP function parse_ini_file behind the scenes.
string | $filename | Filename |
integer | $mode | INI_SCANNER_NORMAL | INI_SCANNER_RAW |
when file not found
when file is not readable
when parse ini file failed
sync() : \Config_Lite
sync the file to the object
like `save', but after written the data, reads the data back into the object. This method is not for the average use-case, ie. for testing.
when file is not set, write or readable
setSingleTickDelimiter() : \Config_Lite
set string delimiter to single tick (')
setDoubleTickDelimiter() : \Config_Lite
set string delimiter to double tick (")
setFlags(integer $flags = LOCK_EX) : \Config_Lite
Set Flags ( FILE_USE_INCLUDE_PATH | FILE_APPEND | LOCK_EX ) for file-put-contents
integer | $flags | any or binary combined |
write(string $filename, array $sectionsarray, integer $flags = null) : boolean
generic write ini config file, to save use `save'.
writes the global options and sections with normalized Values, that means "bool" values to human readable representation, doublequotes strings and numeric values without any quotes. prepends a php exit if suffix is php, it is valid to write an empty Config file, this method is used by save and is public for explicit usage, eg. if you do not want to hold the whole configuration in the object.
string | $filename | filename |
array | $sectionsarray | array with sections |
integer | $flags | for file-put-contents |
when file is not writeable
when write failed
getString(string $sec, string $key, mixed $default = null) : string
returns a stripslashed string
string | $sec | Section |
string | $key | Key |
mixed | $default | default return value |
when config is empty and no default value is given
key not found and no default value is given
get(string $sec = null, string $key = null, mixed $default = null) : mixed
get an option by section, a global option or all sections and options
to get an option by section, call get with a section and the option.
To get a global option call get' with null as section. Just call
get' without any parameters to get all sections and options.
The third parameter is an optional default value to return,
if the option is not set, this is practical when dealing with
editable files, to keep an application stable with default settings.
string | $sec | Section|null - null to get global option |
string | $key | Key |
mixed | $default | return default value if is $key is not set |
when config is empty and no default value is given
key not found and no default value is given
getBool(string $sec, string $key, boolean $default = null) : boolean
returns a boolean for strict equality comparison
returns "on", "yes", 1, "true" as TRUE and no given value or "off", "no", 0, "false" as FALSE
string | $sec | Section |
string | $key | Key |
boolean | $default | return default value if is $key is not set |
when the configuration is empty and no default value is given
when is not a boolean and no default array is given
when key not found and no default array is given
getSection(string $sec, array $default = null) : array
returns an array of options of the given section
string | $sec | Section |
array | $default | return default array if $sec is not set |
when config is empty and no default array is given
when key not found and no default array is given
clear() : \Config_Lite
removes all sections and global options
setString(string $sec, string $key, mixed $value = null) : \Config_Lite
like set, but adds slashes to the value
creates new section if necessary and overrides existing keys.
string | $sec | Section |
string | $key | Key |
mixed | $value | Value |
when given key is an array
set(string $sec, string $key, mixed $value = null) : \Config_Lite
to add key/value pairs
creates new section if necessary and overrides existing keys. To set a global, "sectionless" value, call set with null as section.
string | $sec | Section |
string | $key | Key |
mixed | $value | Value |
when given key is an array
setSection(string $sec, array $pairs) : \Config_Lite
set a given array with key/value pairs to a section, creates a new section if necessary.
string | $sec | Section |
array | $pairs | Keys and Values as Array ('key' => 'value') |
array $pairs expected
setFilename(string $filename) : \Config_Lite
filename to read or save
the full filename with suffix, ie. `[PATH/]
string | $filename | Filename |
setLinebreak(string $linebreakchars) : \Config_Lite
set the line break (newline) chars
line-break defaults to Unix Newline "\n", set to support other linebreaks, eg. windows user textfiles "\r\n"
string | $linebreakchars | chars |
setProcessSections(boolean $processSections) : \Config_Lite
Sets whether or not sections should be processed
If true, values for each section will be placed into a sub-array for the section. If false, all values will be placed in the global scope.
boolean | $processSections |
|
setQuoteStrings(boolean $quoteStrings) : \Config_Lite
Sets whether or not to doubleQuote
If true, everything but bool and numeric values get doublequoted.
boolean | $quoteStrings |
|
__construct(string $filename = null, integer $flags = null, integer $mode)
takes an optional filename, if the file exists, also reads it.
the save' and
read' methods relies on a setted filename,
but you can also use `setFilename' to set the filename.
string | $filename |
|
integer | $flags |
|
integer | $mode |
|