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

Class: Config_Lite

Source Location: /Config_Lite-0.1.5/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 ]

$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 828]

Config_Lite __construct( [string $filename = 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

[ Top ]

buildOutputString   [line 230]

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 554]

void clear( )

removes all sections and global options
  • Access: public

[ Top ]

count   [line 791]

int count( )

implemented for interface Countable

[ Top ]

get   [line 338]

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 387]

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 654]

string getFilename( )

returns the current filename
  • Access: public

[ Top ]

getIterator   [line 780]

Iterator getIterator( )

implemented for interface IteratorAggregate

[ Top ]

getSection   [line 449]

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 297]

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 490]

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 474]

bool hasSection( string $sec)

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

Parameters:

string   $sec     Section

[ Top ]

isBool   [line 165]

bool isBool( string $value)

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

Parameters:

string   $value     value

[ Top ]

normalizeValue   [line 177]

string normalizeValue( string $value)

normalize a Value by determining the Type
  • Access: protected

Parameters:

string   $value     value

[ Top ]

offsetExists   [line 743]

bool offsetExists( string $offset)

implemented for interface ArrayAccess
  • Access: public

Parameters:

string   $offset     - section, implemented by ArrayAccess

[ Top ]

offsetGet   [line 767]

mixed offsetGet( string $offset)

implemented for interface ArrayAccess
  • Access: public

Parameters:

string   $offset     - section, implemented by ArrayAccess

[ Top ]

offsetSet   [line 731]

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 755]

void offsetUnset( string $offset)

implemented for interface ArrayAccess
  • Access: public

Parameters:

string   $offset     - section, implemented by ArrayAccess

[ Top ]

read   [line 101]

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 510]

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 541]

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 129]

bool save( )

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

[ Top ]

serialize   [line 802]

int serialize( )

implemented for interface Serializable

[ Top ]

set   [line 593]

$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 643]

$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 ]

setLinebreak   [line 670]

$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 687]

$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 703]

$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 621]

$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 571]

$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 145]

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 276]

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 814]

void unserialize( string $serializedData)

implemented for interface Serializable
  • Access: public

Parameters:

string   $serializedData     for instance

[ Top ]

write   [line 209]

bool write( string $filename, array $sectionsarray)

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

[ Top ]

__toString   [line 718]

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 Tue, 16 Apr 2013 17:30:03 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.