Gumbo PHP Library API Documentation
Config
[
class tree
] [
index
] [
all elements
]
Todo List
Packages:
Buffer
Collection
Composite
Config
Converter
Curl
Date
DB
Debug
Encryption
Error
Factory
Filter
Flyweight
Http
Input
Iterator
List
Load
Lockable
Log
Map
Number
Observer
Output
Query
Record
Router
Session
Setting
Singleton
Template
Timer
Utility
Valid
Source for file Php.class.php
Documentation is available at
Php.class.php
<?php
/**
* Gumbo Library Framework
*
* LICENSE
* This library is being released under the terms of the New BSD License. A
* copy of the license is packaged with the software (LICENSE.txt). If no
* copy is found, a copy of the license template can be found at:
* http://www.opensource.org/licenses/bsd-license.php
*
*
@category
Gumbo
*
@package
Config
*
@copyright
Copyright (c) 2007, iBayou, Michael Luster
*
@license
http://www.opensource.org/licenses/bsd-license.php New BSD License
*
@author
Michael Luster <mluster79@yahoo.com>
*
@link
http://sourceforge.net/projects/phpgumbo
*
@version
0.0.1
*/
/**
* Config PHP Reader
*
* A PHP Reader will simply include the defined PHP file, and parse an array into
* a Composite object
*
*
@category
Gumbo
*
@package
Config
*
@copyright
Copyright (c) 2007, iBayou, Michael Luster
*
@license
http://www.opensource.org/licenses/bsd-license.php New BSD License
*
@author
Michael Luster <mluster79@yahoo.com>
*
@link
http://sourceforge.net/projects/phpgumbo
*
@desc
Config PHP Reader
*
@version
0.0.1
*/
gumbo_load
(
"Interface_Config_Reader"
)
;
class
Gumbo_Config_Reader_Php
implements
Gumbo_Interface_Config_Reader
{
/**
@var
string
$_name
config variable name */
private
$_name
=
"config"
;
/**
* Constructor
*
@param
string
$name
config variable name
*/
public
function
__construct
(
$name
=
null
)
{
if
(
!
is_null
(
$name
))
{
$this
->
setName
(
$name
)
;
}
}
/** ACTION METHODS **/
/**
* Reads the given configuration into memory, and returns the results
*
@param
string
$file
*
@return
Gumbo_Interface_Composite
*
@throws
Gumbo_Exception
*
@uses
Gumbo_Converter, Gumbo_Branch
*/
public
function
read
(
$file
)
{
gumbo_load
(
"Interface_Composite"
)
;
gumbo_load
(
"Branch"
)
;
gumbo_load
(
"Converter"
)
;
try
{
// verify precondition
if
(
!
is_string
(
$file
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Argument
'
file
:
str
' => {
$file
}
:
"
.
gettype
(
$file
))
;
}
if
(
!
file_exists
(
$file
))
{
throw
new
Gumbo_Exception
(
"
File
Not
Found
: {
$file
}
"
)
;
}
$name
=
$this
->
getName
(
)
;
// include the file into memory
include
(
$file
)
;
if
(
!
isset
(
$
$name
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Configuration
Variable
: {
$name
}
"
)
;
}
if
(
!
is_array
(
$
$name
))
{
throw
new
Gumbo_Exception
(
"Invalid Variable Type: "
.
gettype
(
$
$name
))
;
}
$obj
=
new
Gumbo_Converter
(
)
;
if
((
$res
=
$obj
->
factory
(
"array"
)
->
convert
(
$
$name
,
"composite"
))
instanceof
Gumbo_Interface_Composite
)
{
return
$res
;
}
}
catch
(
Gumbo_Exception
$e
)
{
$e
->
setFunction
(
__METHOD__
)
;
gumbo_trigger
(
$e
)
;
}
return
new
Gumbo_Branch
(
)
;
}
/** MUTATOR METHODS **/
/**
* Sets the config variable name
*
@precondition
valid PHP variable name
*
@postcondition
removes non alpha-numeric (excluding underscores) from the name
*
@param
string
$name
*/
public
function
setName
(
$name
)
{
try
{
// verify precondition
if
(
!
is_string
(
$name
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Argument
'
name
:
str
' => {
$name
}
:
"
.
getType
(
$name
))
;
}
if
(
!
ereg
(
"[_a-zA-Z]"
,
substr
(
$name
,
0
,
1
)))
{
throw
new
Gumbo_Exception
(
"
Invalid
Variable
Name
: {
$name
}
"
)
;
}
$this
->
_name
=
preg_replace
(
"[^a-zA-Z0-9_]"
,
""
,
$name
)
;
}
catch
(
Gumbo_Exception
$e
)
{
$e
->
setFunction
(
__METHOD__
)
;
gumbo_trigger
(
$e
)
;
}
}
/** ACCESSOR METHODS **/
/**
* Returns the Config variable name
*
@return
string
*/
public
function
getName
(
)
{
return
$this
->
_name
;
}
}
?>