PHP Класс Config_Lite

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
Автор: Patrick C. Engel ([email protected])
Наследование: implements ArrayAccess, implements IteratorAggregate, implements Countable, implements Serializable
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$delim string string delimiter
$filename string filename
$flags integer flags for file-put-contents
$linebreak string line-break chars, default *x: "\n", windows: "\r\n"
$processSections boolean parseSections - if true, sections will be processed
$quoteStrings boolean quote Strings - if true, writes ini files with doublequoted strings
$sections array sections, holds the config sections

Открытые методы

Метод Описание
__construct ( string $filename = null, integer $flags = null, integer $mode ) takes an optional filename, if the file exists, also reads it.
__toString ( ) : string text presentation of the config object
clear ( ) : Config_Lite removes all sections and global options
count ( ) : integer implemented for interface Countable
get ( string $sec = null, string $key = null, mixed $default = null ) : mixed get an option by section, a global option or all sections and options
getBool ( string $sec, string $key, boolean $default = null ) : boolean returns a boolean for strict equality comparison
getFilename ( ) : string returns the current filename
getIterator ( ) : Iterator implemented for interface IteratorAggregate
getSection ( string $sec, array $default = null ) : array returns an array of options of the given section
getString ( string $sec, string $key, mixed $default = null ) : string returns a stripslashed string
has ( string $sec, string $key = null ) : boolean tests if a section or an option of a section exists
hasSection ( string $sec ) : boolean returns true if the given section exists, otherwise false
offsetExists ( string $offset ) : boolean implemented for interface ArrayAccess
offsetGet ( string $offset ) : mixed implemented for interface ArrayAccess
offsetSet ( string $offset, mixed $value ) : void implemented for interface ArrayAccess
offsetUnset ( string $offset ) : void implemented for interface ArrayAccess
read ( string $filename = null, integer $mode = INI_SCANNER_NORMAL ) : Config_Lite the read method parses the optional given filename or already setted filename.
remove ( string $sec, string $key = null ) : void remove a section or an option of a section
removeSection ( string $sec ) : void remove section by name
save ( ) : boolean save the object to the filename (active record style)
serialize ( ) : integer implemented for interface Serializable
set ( string $sec, string $key, mixed $value = null ) : Config_Lite to add key/value pairs
setDoubleTickDelimiter ( ) : Config_Lite set string delimiter to double tick (")
setFilename ( string $filename ) : Config_Lite filename to read or save
setFlags ( integer $flags = LOCK_EX ) : Config_Lite Set Flags ( FILE_USE_INCLUDE_PATH | FILE_APPEND | LOCK_EX ) for file-put-contents
setLinebreak ( string $linebreakchars ) : Config_Lite set the line break (newline) chars
setProcessSections ( boolean $processSections ) : Config_Lite Sets whether or not sections should be processed
setQuoteStrings ( boolean $quoteStrings ) : Config_Lite Sets whether or not to doubleQuote
setSection ( string $sec, array $pairs ) : Config_Lite set a given array with key/value pairs to a section, creates a new section if necessary.
setSingleTickDelimiter ( ) : Config_Lite set string delimiter to single tick (')
setString ( string $sec, string $key, mixed $value = null ) : Config_Lite like set, but adds slashes to the value
sync ( ) : Config_Lite sync the file to the object
toBool ( string $value ) : string converts string to a representable Config Bool Format
unserialize ( string $serializedData ) : void implemented for interface Serializable
write ( string $filename, array $sectionsarray, integer $flags = null ) : boolean generic write ini config file, to save use `save'.

Защищенные методы

Метод Описание
buildOutputString ( array $sectionsarray ) : string Generated the output of the ini file, suitable for echo'ing or writing back to the ini file.
isBool ( string $value ) : boolean detect Type "bool" by String Value to keep those "untouched"
normalizeValue ( string $value ) : string normalize a Value by determining the Type

Описание методов

__construct() публичный Метод

the save' and read' methods relies on a setted filename, but you can also use `setFilename' to set the filename.
public __construct ( string $filename = null, integer $flags = null, integer $mode )
$filename string - "INI Style" Text Config File
$flags integer - flags for file_put_contents, eg. FILE_APPEND
$mode integer - set scannermode

__toString() публичный Метод

since a empty config is valid, it would return a empty string in that case.
public __toString ( ) : string
Результат string

buildOutputString() защищенный Метод

Generated the output of the ini file, suitable for echo'ing or writing back to the ini file.
protected buildOutputString ( array $sectionsarray ) : string
$sectionsarray array array of ini data
Результат string

clear() публичный Метод

removes all sections and global options
public clear ( ) : Config_Lite
Результат Config_Lite

count() публичный Метод

implemented for interface Countable
См. также: http://php.net.countable
public count ( ) : integer
Результат integer

get() публичный Метод

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.
public get ( string $sec = null, string $key = null, mixed $default = null ) : mixed
$sec string Section|null - null to get global option
$key string Key
$default mixed return default value if is $key is not set
Результат mixed

getBool() публичный Метод

returns "on", "yes", 1, "true" as TRUE and no given value or "off", "no", 0, "false" as FALSE
public getBool ( string $sec, string $key, boolean $default = null ) : boolean
$sec string Section
$key string Key
$default boolean return default value if is $key is not set
Результат boolean

getFilename() публичный Метод

returns the current filename
public getFilename ( ) : string
Результат string

getIterator() публичный Метод

implemented for interface IteratorAggregate
См. также: http://www.php.net/~helly/php/ext/spl/interfaceIterator.html
public getIterator ( ) : Iterator
Результат Iterator

getSection() публичный Метод

returns an array of options of the given section
public getSection ( string $sec, array $default = null ) : array
$sec string Section
$default array return default array if $sec is not set
Результат array

getString() публичный Метод

returns a stripslashed string
public getString ( string $sec, string $key, mixed $default = null ) : string
$sec string Section
$key string Key
$default mixed default return value
Результат string

has() публичный Метод

tests if a section or an option of a section exists
public has ( string $sec, string $key = null ) : boolean
$sec string Section
$key string Key
Результат boolean

hasSection() публичный Метод

returns true if the given section exists, otherwise false
public hasSection ( string $sec ) : boolean
$sec string Section
Результат boolean

isBool() защищенный Метод

detect Type "bool" by String Value to keep those "untouched"
protected isBool ( string $value ) : boolean
$value string value
Результат boolean

normalizeValue() защищенный Метод

normalize a Value by determining the Type
protected normalizeValue ( string $value ) : string
$value string value
Результат string

offsetExists() публичный Метод

implemented for interface ArrayAccess
public offsetExists ( string $offset ) : boolean
$offset string - section, implemented by ArrayAccess
Результат boolean

offsetGet() публичный Метод

implemented for interface ArrayAccess
public offsetGet ( string $offset ) : mixed
$offset string - section, implemented by ArrayAccess
Результат mixed

offsetSet() публичный Метод

implemented for interface ArrayAccess
public offsetSet ( string $offset, mixed $value ) : void
$offset string section, implemented by ArrayAccess
$value mixed KVP, implemented by ArrayAccess
Результат void

offsetUnset() публичный Метод

implemented for interface ArrayAccess
public offsetUnset ( string $offset ) : void
$offset string - section, implemented by ArrayAccess
Результат void

read() публичный Метод

this method uses the native PHP function parse_ini_file behind the scenes.
public read ( string $filename = null, integer $mode = INI_SCANNER_NORMAL ) : Config_Lite
$filename string Filename
$mode integer INI_SCANNER_NORMAL | INI_SCANNER_RAW
Результат Config_Lite

remove() публичный Метод

remove a section or an option of a section
public remove ( string $sec, string $key = null ) : void
$sec string Section
$key string Key
Результат void

removeSection() публичный Метод

remove section by name
public removeSection ( string $sec ) : void
$sec string Section
Результат void

save() публичный Метод

save the object to the filename (active record style)
public save ( ) : boolean
Результат boolean

serialize() публичный Метод

implemented for interface Serializable
См. также: http://php.net/manual/en/class.serializable.php
public serialize ( ) : integer
Результат integer

set() публичный Метод

creates new section if necessary and overrides existing keys. To set a global, "sectionless" value, call set with null as section.
public set ( string $sec, string $key, mixed $value = null ) : Config_Lite
$sec string Section
$key string Key
$value mixed Value
Результат Config_Lite

setDoubleTickDelimiter() публичный Метод

set string delimiter to double tick (")
public setDoubleTickDelimiter ( ) : Config_Lite
Результат Config_Lite

setFilename() публичный Метод

the full filename with suffix, ie. `[PATH/].ini'. you can also set the filename as parameter to the constructor.
public setFilename ( string $filename ) : Config_Lite
$filename string Filename
Результат Config_Lite

setFlags() публичный Метод

Set Flags ( FILE_USE_INCLUDE_PATH | FILE_APPEND | LOCK_EX ) for file-put-contents
public setFlags ( integer $flags = LOCK_EX ) : Config_Lite
$flags integer any or binary combined
Результат Config_Lite

setLinebreak() публичный Метод

line-break defaults to Unix Newline "\n", set to support other linebreaks, eg. windows user textfiles "\r\n"
public setLinebreak ( string $linebreakchars ) : Config_Lite
$linebreakchars string chars
Результат Config_Lite

setProcessSections() публичный Метод

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.
public setProcessSections ( boolean $processSections ) : Config_Lite
$processSections boolean - if true, sections will be processed
Результат Config_Lite

setQuoteStrings() публичный Метод

If true, everything but bool and numeric values get doublequoted.
public setQuoteStrings ( boolean $quoteStrings ) : Config_Lite
$quoteStrings boolean - if true, Strings get doubleQuoted
Результат Config_Lite

setSection() публичный Метод

set a given array with key/value pairs to a section, creates a new section if necessary.
public setSection ( string $sec, array $pairs ) : Config_Lite
$sec string Section
$pairs array Keys and Values as Array ('key' => 'value')
Результат Config_Lite

setSingleTickDelimiter() публичный Метод

set string delimiter to single tick (')
public setSingleTickDelimiter ( ) : Config_Lite
Результат Config_Lite

setString() публичный Метод

creates new section if necessary and overrides existing keys.
public setString ( string $sec, string $key, mixed $value = null ) : Config_Lite
$sec string Section
$key string Key
$value mixed Value
Результат Config_Lite

sync() публичный Метод

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.
public sync ( ) : Config_Lite
Результат Config_Lite

toBool() публичный Метод

converts string to a representable Config Bool Format
public toBool ( string $value ) : string
$value string value
Результат string

unserialize() публичный Метод

implemented for interface Serializable
public unserialize ( string $serializedData ) : void
$serializedData string for instance
Результат void

write() публичный Метод

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.
public write ( string $filename, array $sectionsarray, integer $flags = null ) : boolean
$filename string filename
$sectionsarray array array with sections
$flags integer for file-put-contents
Результат boolean

Описание свойств

$delim защищенное свойство

string delimiter
protected string $delim
Результат string

$filename защищенное свойство

filename
protected string $filename
Результат string

$flags защищенное свойство

flags for file-put-contents
protected int $flags
Результат integer

$linebreak защищенное свойство

line-break chars, default *x: "\n", windows: "\r\n"
protected string $linebreak
Результат string

$processSections защищенное свойство

parseSections - if true, sections will be processed
protected bool $processSections
Результат boolean

$quoteStrings защищенное свойство

quote Strings - if true, writes ini files with doublequoted strings
protected bool $quoteStrings
Результат boolean

$sections защищенное свойство

sections, holds the config sections
protected array $sections
Результат array