Config_Lite
[ class tree: Config_Lite ] [ index: Config_Lite ] [ all elements ]

Class: Config_Lite

Source Location: /Config_Lite-0.2.1/Config/Lite.php

Class Overview


Config_Lite Class


Author(s):

Copyright:

  • 2010-2011 <pce@php.net>

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 41]
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



[ Top ]


Class Variables

$filename =

[line 54]

filename
  • Access: protected

Type:   string


[ Top ]

$flags =  0

[line 92]

flags for file-put-contents
  • Access: protected

Type:   int


[ Top ]

$linebreak =  "\n"

[line 70]

line-break chars, default *x: "\n", windows: "\r\n"
  • Access: protected

Type:   string


[ Top ]

$processSections =  true

[line 77]

parseSections - if true, sections will be processed
  • Access: protected

Type:   bool


[ Top ]

$quoteStrings =  true

[line 85]

quote Strings - if true, writes ini files with doublequoted strings
  • Access: protected

Type:   bool


[ Top ]

$sections =

[line 48]

sections, holds the config sections
  • Access: protected

Type:   array


[ Top ]



Method Detail

__construct (Constructor)   [line 854]

Config_Lite __construct( [string $filename = null], [int $flags = null])

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.

  • Access: public

Parameters:

string   $filename     - "INI Style" Text Config File
int   $flags     
  • setFlags

[ Top ]

buildOutputString   [line 255]

string buildOutputString( string $sectionsarray)

Generated the output of the ini file, suitable for echo'ing or writing back to the ini file.
  • Access: protected

Parameters:

string   $sectionsarray     array of ini data

[ Top ]

clear   [line 579]

void clear( )

removes all sections and global options
  • Access: public

[ Top ]

count   [line 816]

int count( )

implemented for interface Countable

[ Top ]

get   [line 363]

mixed get( [string $sec = null], [string $key = null], [mixed $default = null])

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.

  • Throws: Config_Lite_Exception_UnexpectedValue key not found and no default value is given
  • Throws: Config_Lite_Exception when config is empty and no default value is given
  • Access: public

Parameters:

string   $sec     Section|null - null to get global option
string   $key     Key
mixed   $default     return default value if is $key is not set

[ Top ]

getBool   [line 412]

bool getBool( string $sec, string $key, [bool $default = null])

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

  • Throws: Config_Lite_Exception_Runtime when the configuration is empty and no default value is given
  • Throws: Config_Lite_Exception_InvalidArgument when is not a boolean and no default array is given
  • Throws: Config_Lite_Exception_UnexpectedValue when key not found and no default array is given
  • Access: public

Parameters:

string   $sec     Section
string   $key     Key
bool   $default     return default value if is $key is not set

[ Top ]

getFilename   [line 679]

string getFilename( )

returns the current filename
  • Access: public

[ Top ]

getIterator   [line 805]

Iterator getIterator( )

implemented for interface IteratorAggregate

[ Top ]

getSection   [line 474]

array getSection( string $sec, [array $default = null])

returns an array of options of the given section
  • Throws: Config_Lite_Exception_UnexpectedValue when key not found and no default array is given
  • Throws: Config_Lite_Exception_Runtime when config is empty and no default array is given
  • Access: public

Parameters:

string   $sec     Section
array   $default     return default array if $sec is not set

[ Top ]

getString   [line 322]

string getString( string $sec, string $key, [mixed $default = null])

returns a stripslashed string
  • Throws: Config_Lite_Exception_UnexpectedValue key not found and no default value is given
  • Throws: Config_Lite_Exception_Runtime when config is empty and no default value is given
  • Access: public

Parameters:

string   $sec     Section
string   $key     Key
mixed   $default     default return value

[ Top ]

has   [line 515]

bool has( string $sec, [string $key = null])

tests if a section or an option of a section exists
  • Access: public

Parameters:

string   $sec     Section
string   $key     Key

[ Top ]

hasSection   [line 499]

bool hasSection( string $sec)

returns true if the given section exists, otherwise false
  • Access: public

Parameters:

string   $sec     Section

[ Top ]

isBool   [line 174]

bool isBool( string $value)

detect Type "bool" by String Value to keep those "untouched"
  • Access: protected

Parameters:

string   $value     value

[ Top ]

normalizeValue   [line 186]

string normalizeValue( string $value)

normalize a Value by determining the Type
  • Access: protected

Parameters:

string   $value     value

[ Top ]

offsetExists   [line 768]

bool offsetExists( string $offset)

implemented for interface ArrayAccess
  • Access: public

Parameters:

string   $offset     - section, implemented by ArrayAccess

[ Top ]

offsetGet   [line 792]

mixed offsetGet( string $offset)

implemented for interface ArrayAccess
  • Access: public

Parameters:

string   $offset     - section, implemented by ArrayAccess

[ Top ]

offsetSet   [line 756]

void offsetSet( string $offset, mixed $value)

implemented for interface ArrayAccess
  • Access: public

Parameters:

string   $offset     section, implemented by ArrayAccess
mixed   $value     KVP, implemented by ArrayAccess

[ Top ]

offsetUnset   [line 780]

void offsetUnset( string $offset)

implemented for interface ArrayAccess
  • Access: public

Parameters:

string   $offset     - section, implemented by ArrayAccess

[ Top ]

read   [line 108]

void read( [string $filename = null])

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.

  • Throws: Config_Lite_Exception_Runtime when file not found
  • Throws: Config_Lite_Exception_Runtime when file is not readable
  • Throws: Config_Lite_Exception_Runtime when parse ini file failed
  • Access: public

Parameters:

string   $filename     Filename

[ Top ]

remove   [line 535]

void remove( string $sec, [string $key = null])

remove a section or an option of a section
  • Throws: Config_Lite_Exception_UnexpectedValue when given Section not exists
  • Access: public

Parameters:

string   $sec     Section
string   $key     Key

[ Top ]

removeSection   [line 566]

void removeSection( string $sec)

remove section by name
  • Throws: Config_Lite_Exception_UnexpectedValue when given Section not exists
  • Access: public

Parameters:

string   $sec     Section

[ Top ]

save   [line 137]

bool save( )

save the object to the already setted filename (active record style)
  • Access: public

[ Top ]

serialize   [line 827]

int serialize( )

implemented for interface Serializable

[ Top ]

set   [line 618]

$this set( string $sec, string $key, [mixed $value = null])

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.

  • Throws: Config_Lite_Exception when given key is an array
  • Access: public

Parameters:

string   $sec     Section
string   $key     Key
mixed   $value     Value

[ Top ]

setFilename   [line 668]

$this setFilename( string $filename)

filename to read or save

the full filename with suffix, ie. `[PATH/]<ApplicationName>.ini'. you can also set the filename as parameter to the constructor.

  • Access: public

Parameters:

string   $filename     Filename

[ Top ]

setFlags   [line 209]

Config_Lite setFlags( [int $flags = LOCK_EX])

Set Flags ( FILE_USE_INCLUDE_PATH | FILE_APPEND | LOCK_EX ) for file-put-contents
  • Access: public

Parameters:

int   $flags     any or binary combined

[ Top ]

setLinebreak   [line 695]

$this setLinebreak( string $linebreakchars)

set the line break (newline) chars

line-break defaults to Unix Newline "\n", set to support other linebreaks, eg. windows user textfiles "\r\n"

  • Access: public

Parameters:

string   $linebreakchars     chars

[ Top ]

setProcessSections   [line 712]

$this setProcessSections( bool $processSections)

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.

  • Access: public

Parameters:

bool   $processSections     - if true, sections will be processed

[ Top ]

setQuoteStrings   [line 728]

$this setQuoteStrings( bool $quoteStrings)

Sets whether or not to doubleQuote

If true, everything but bool and numeric values get doublequoted.

  • Access: public

Parameters:

bool   $quoteStrings     - if true, Strings get doubleQuoted

[ Top ]

setSection   [line 646]

$this setSection( string $sec, array $pairs)

set a given array with key/value pairs to a section, creates a new section if necessary.
  • Throws: Config_Lite_Exception_InvalidArgument array $pairs expected
  • Access: public

Parameters:

string   $sec     Section
array   $pairs     Keys and Values as Array ('key' => 'value')

[ Top ]

setString   [line 596]

$this setString( string $sec, string $key, [mixed $value = null])

like set, but adds slashes to the value

creates new section if necessary and overrides existing keys.

  • Throws: Config_Lite_Exception_InvalidArgument when given key is an array
  • Access: public

Parameters:

string   $sec     Section
string   $key     Key
mixed   $value     Value

[ Top ]

sync   [line 153]

void sync( )

sync the file to the object

like `save', but after written the data, reads the data back into the object. The method is inspired by QTSettings. Ideal for testing.

  • Throws: Config_Lite_Exception_Runtime when file is not set, write or readable
  • Access: public

[ Top ]

toBool   [line 301]

string toBool( string $value)

converts string to a representable Config Bool Format
  • Throws: Config_Lite_Exception_UnexpectedValue when format is unknown
  • Access: public

Parameters:

string   $value     value

[ Top ]

unserialize   [line 839]

void unserialize( string $serializedData)

implemented for interface Serializable
  • Access: public

Parameters:

string   $serializedData     for instance

[ Top ]

write   [line 234]

bool write( string $filename, array $sectionsarray, [int $flags = null])

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.

  • Throws: Config_Lite_Exception_Runtime when write failed
  • Throws: Config_Lite_Exception_Runtime when file is not writeable
  • Access: public

Parameters:

string   $filename     filename
array   $sectionsarray     array with sections
int   $flags     for file-put-contents

[ Top ]

__toString   [line 743]

string __toString( )

text presentation of the config object

since a empty config is valid, it would return a empty string in that case.

  • Throws: Config_Lite_Exception_Runtime
  • Access: public

[ Top ]


Documentation generated on Sat, 26 Oct 2013 11:00:04 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.