Gumbo PHP Library API Documentation
Setting
[
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 Setting.class.php
Documentation is available at
Setting.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
Setting
*
@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
*/
/**
* Setting Class
*
*
@category
Gumbo
*
@package
Setting
*
@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
Setting Class
*
@version
0.0.1
*/
gumbo_load
(
"Interface_Setting"
)
;
gumbo_load
(
"List"
)
;
class
Gumbo_Setting
extends
Gumbo_List
implements
Gumbo_Interface_Setting
{
/**
* Constructor
*
@param
array
$args
key=>val pairs
*/
public
function
__construct
(
$args
=
null
)
{
if
(
is_null
(
$args
))
{
$args
=
array
(
)
;
}
if
(
is_array
(
$args
)
&&
count
(
$args
)
>
0
)
{
$this
->
set
(
$args
)
;
}
}
/** ACTION METHODS **/
/**
* Adds a pair value to the setting
*
@postcondition
remove all non-alphanumeric (excluding underscores) characters from $key
*
@param
mixed
$data
*
@param
string
$key
(required)
*
@throws
Gumbo_Exception
*/
public
function
add
(
$data
,
$key
=
null
)
{
try
{
// verify precondition
if
(
!
is_string
(
$key
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Argument
'
key
:
str
' => {
$key
}
:
"
.
gettype
(
$key
))
;
}
$key
=
ereg_replace
(
"[^A-Za-z0-9_]"
,
""
,
$key
)
;
$this
->
_list
[
$key
]
=
$val
;
}
catch
(
Gumbo_Exception
$e
)
{
$e
->
setFunction
(
__METHOD__
)
;
gumbo_trigger
(
$e
)
;
}
}
/**
* Removes a value from the List (not used)
*
@param
mixed
$data
*/
public
function
removeValue
(
$data
)
{
return
;
}
/** MUTATOR METHODS **/
/**
* Sets the setting values
*
@param
string
|
array
$data
(string represents a 'key') associative array of key=>val pairs
*
@param
mixed
$val
*
@throws
Gumbo_Exception
*/
public
function
set
(
$data
,
$val
=
null
)
{
try
{
// verify precondition
if
(
!
is_string
(
$data
)
&&
!
is_array
(
$data
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Argument
'
data
:
str
|
arr
' => {
$data
}
:
"
.
gettype
(
$data
))
;
}
// recursive call
if
(
is_array
(
$data
))
{
foreach
(
$data
as
$key
=>
$val
)
{
if
(
is_array
(
$val
))
{
$this
->
set
(
$val
)
;
}
else
{
$this
->
set
(
$key
,
$val
)
;
}
}
return
;
}
$this
->
add
(
$val
,
$data
)
;
}
catch
(
Gumbo_Exception
$e
)
{
$e
->
setFunction
(
__METHOD__
)
;
gumbo_trigger
(
$e
)
;
}
}
}
?>