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
파일 보기 프로젝트 열기: mescon/Muximux 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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