ConfigParser/ConfigParser.php
- author
- Vítor Brandão <noisebleed@noiselabs.org>
- category
- NoiseLabs
- copyright
- (C) 2011 Vítor Brandão <noisebleed@noiselabs.org>
- package
- ConfigParser
- version
- 0.1.1
- Classes
- ConfigParser
Description
This file is part of NoiseLabs-PHP-ToolKit
NoiseLabs-PHP-ToolKit is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
NoiseLabs-PHP-ToolKit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with NoiseLabs-PHP-ToolKit; if not, see http://www.gnu.org/licenses/.
Copyright (C) 2011 Vítor Brandão noisebleed@noiselabs.org
NoiseLabs\ToolKit\ConfigParser\ConfigParser
- Extends from
- NoiseLabs\ToolKit\ConfigParser\BaseConfigParser
- Implements
- NoiseLabs\ToolKit\ConfigParser\ConfigParserInterface
- author
- Vítor Brandão <noisebleed@noiselabs.org>
- note
- This class does not interpret or write the value-type prefixes used in the Windows Registry extended version of INI syntax.
- Constants
- DEFAULT_SECTION
- HAS_SECTIONS
- Methods
- sections
- addSection
- hasSection
- options
- hasOption
- setOptions
- read
- get
- getInt
- getFloat
- getBoolean
- set
- _buildOptionValueLine
- _buildOutputString
- removeOption
Description
The ConfigParser class implements a basic configuration language which provides a structure similar to what’s found in Microsoft Windows INI files. You can use this to write PHP programs which can be customized by end users easily.
DISCLAIMER: Every docblock was shameless copied or at least adapted from Python's configparser documentation page (version 3.0). See http://docs.python.org/dev/library/configparser.html
Constants
DEFAULT_SECTION
DEFAULT_SECTION = 'DEFAULT'
Details
- value
- DEFAULT
HAS_SECTIONS
HAS_SECTIONS = 'true'
Details
- value
- true
Methods
_buildOptionValueLine
_buildOptionValueLine(
$key, $value
)
:
Arguments
- $key
- $value
Details
- visibility
- protected
- final
- false
- static
- false
_buildOutputString
_buildOutputString(
)
:
Details
- visibility
- protected
- final
- false
- static
- false
addSection
addSection(
$section
)
:
Add a section named section to the instance. If a section by the given name already exists, DuplicateSectionException is raised. If the default section name is passed, InvalidArgumentException is raised.
The name of the section must be a string; if not, InvalidArgumentException is raised too.
Arguments
- $section
Details
- visibility
- public
- final
- false
- static
- false
get
get(
NoiseLabs\ToolKit\ConfigParser\$section $section, NoiseLabs\ToolKit\ConfigParser\$option $option, NoiseLabs\ToolKit\ConfigParser\$fallback $fallback
=
null
)
:
NoiseLabs\ToolKit\ConfigParser\Option
Get an option value for the named section.
If the option doesn't exist in the configuration $defaults is used. If $defaults doesn't have this option too then we look for the $fallback parameter. If everything fails throw a NoOptionException.
Arguments
- $section
- NoiseLabs\ToolKit\ConfigParser\$section
Section name - $option
- NoiseLabs\ToolKit\ConfigParser\$option
Option name - $fallback
- NoiseLabs\ToolKit\ConfigParser\$fallback
A fallback value to use if the option isn't found in the configuration and $defaults.
Output
- NoiseLabs\ToolKit\ConfigParser\Option
- value (if available)
Details
- visibility
- public
- final
- false
- static
- false
- throws
- Couldn't find the desired option in the configuration, $defaults or as a fallback value.
getBoolean
getBoolean(
$section, $option, $fallback
=
null
)
:
A convenience method which coerces the option in the specified section to a Boolean value. Note that the accepted values for the option are '1', 'yes', 'true', and 'on', which cause this method to return TRUE, and '0', 'no', 'false', and 'off', which cause it to return FALSE.
These string values are checked in a case-insensitive manner. Any other value will cause it to raise ValueException.
Arguments
- $section
- $option
- $fallback
Details
- visibility
- public
- final
- false
- static
- false
getFloat
getFloat(
$section, $option, $fallback
=
null
)
:
A convenience method which coerces the option in the specified section to a floating point number.
Arguments
- $section
- $option
- $fallback
Details
- visibility
- public
- final
- false
- static
- false
getInt
getInt(
$section, $option, $fallback
=
null
)
:
A convenience method which coerces the option in the specified section to an integer.
Arguments
- $section
- $option
- $fallback
Details
- visibility
- public
- final
- false
- static
- false
hasOption
hasOption(
$section, $option
)
:
If the given section exists, and contains the given option, return TRUE; otherwise return FALSE. If the specified section is NULL or an empty string, DEFAULT is assumed.
Arguments
- $section
- $option
Details
- visibility
- public
- final
- false
- static
- false
hasSection
hasSection(
$section
)
:
Indicates whether the named section is present in the configuration.
The default section is not acknowledged.
Arguments
- $section
Details
- visibility
- public
- final
- false
- static
- false
options
options(
$section
)
:
Return a list of options available in the specified section.
Arguments
- $section
Details
- visibility
- public
- final
- false
- static
- false
read
read(
$filenames
=
array
)
:
Arguments
- $filenames
Details
- visibility
- public
- final
- false
- static
- false
removeOption
removeOption(
$section, $option
)
:
Remove the specified option from the specified section. If the section does not exist, raise NoSectionException. If the option existed to be removed, return TRUE; otherwise return FALSE.
Arguments
- $section
- $option
Details
- visibility
- public
- final
- false
- static
- false
sections
sections(
)
:
Return a list of the sections available; the default section is not included in the list.
Details
- visibility
- public
- final
- false
- static
- false
set
set(
$section, $option, $value
)
:
If the given section exists, set the given option to the specified value; otherwise raise NoSectionException.
Arguments
- $section
- $option
- $value
Details
- visibility
- public
- final
- false
- static
- false
- todo
- Option and value must be strings; if not, TypeException is raised.
setOptions
setOptions(
$section, $options
=
array
)
:
Arguments
- $section
- $options
Details
- visibility
- public
- final
- false
- static
- false
- throws
- if section doesn't exist