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

Class: Config_Lite

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

Class Overview


Config_Lite Class


Author(s):

Copyright:

  • 2010-2015 <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

$delim =  '"'

[line 99]

string delimiter
  • Access: protected

Type:   string


[ Top ]

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

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

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   — 
  • flags for file_put_contents, eg. FILE_APPEND
int   $mode   — 
  • set scannermode

[ Top ]

buildOutputString   [line 285]

string buildOutputString( array $sectionsarray)

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

Parameters:

array   $sectionsarray   —  array of ini data

[ Top ]

clear   [line 608]

Config_Lite clear( )

removes all sections and global options
  • Access: public

[ Top ]

count   [line 846]

int count( )

implemented for interface Countable

[ Top ]

get   [line 393]

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

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

string getFilename( )

returns the current filename
  • Access: public

[ Top ]

getIterator   [line 835]

Iterator getIterator( )

implemented for interface IteratorAggregate

[ Top ]

getSection   [line 504]

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

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

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

bool hasSection( string $sec)

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

Parameters:

string   $sec   —  Section

[ Top ]

isBool   [line 183]

bool isBool( string $value)

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

Parameters:

string   $value   —  value

[ Top ]

normalizeValue   [line 195]

string normalizeValue( string $value)

normalize a Value by determining the Type
  • Access: protected

Parameters:

string   $value   —  value

[ Top ]

offsetExists   [line 798]

bool offsetExists( string $offset)

implemented for interface ArrayAccess
  • Access: public

Parameters:

string   $offset   —  - section, implemented by ArrayAccess

[ Top ]

offsetGet   [line 822]

mixed offsetGet( string $offset)

implemented for interface ArrayAccess
  • Access: public

Parameters:

string   $offset   —  - section, implemented by ArrayAccess

[ Top ]

offsetSet   [line 786]

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

void offsetUnset( string $offset)

implemented for interface ArrayAccess
  • Access: public

Parameters:

string   $offset   —  - section, implemented by ArrayAccess

[ Top ]

read   [line 116]

Config_Lite read( [string $filename = null], [int $mode = INI_SCANNER_NORMAL])

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
int   $mode   —  INI_SCANNER_NORMAL | INI_SCANNER_RAW

[ Top ]

remove   [line 565]

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

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

bool save( )

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

[ Top ]

serialize   [line 857]

int serialize( )

implemented for interface Serializable

[ Top ]

set   [line 648]

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

setDoubleTickDelimiter   [line 225]

Config_Lite setDoubleTickDelimiter( )

set string delimiter to double tick (")
  • Access: public

[ Top ]

setFilename   [line 698]

Config_Lite 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 239]

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

Config_Lite 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 742]

Config_Lite 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 758]

Config_Lite 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 676]

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

setSingleTickDelimiter   [line 214]

Config_Lite setSingleTickDelimiter( )

set string delimiter to single tick (')
  • Access: public

[ Top ]

setString   [line 626]

Config_Lite 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 162]

Config_Lite sync( )

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.

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

[ Top ]

toBool   [line 331]

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

void unserialize( string $serializedData)

implemented for interface Serializable
  • Access: public

Parameters:

string   $serializedData   —  for instance

[ Top ]

write   [line 264]

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

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 Mon, 23 Feb 2015 14:00:02 +0000 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.