Gumbo PHP Library API Documentation
Input
[
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 Input.class.php
Documentation is available at
Input.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
Input
*
@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
*/
/**
* Input Class
*
*
@category
Gumbo
*
@package
Input
*
@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
Input Class
*
@version
0.0.1
*/
gumbo_load
(
"Interface_Input"
)
;
gumbo_load
(
"Constraint"
)
;
class
Gumbo_Input
implements
Gumbo_Interface_Input
{
/**
@var
Gumbo_Interface_Constraint
$_constraints
*/
private
$_constraints
=
array
(
)
;
/**
@var
array
$_constraints_return
indication of which Constraints return values */
private
$_constraints_return
=
array
(
)
;
/**
@var
mixed
$_data_raw
initial data */
private
$_data_raw
;
/**
@var
mixed
$_data_clean
clean data */
private
$_data_clean
;
/**
@var
bool
$_clean
*/
private
$_clean
=
false
;
/**
@var
bool
$_checked
*/
private
$_checked
=
false
;
/**
@var
bool
$_run_thru
*/
private
$_run_thru
=
true
;
/**
* Constructor
*
@param
mixed
$data
data to be checked
*/
public
function
__construct
(
$data
=
null
)
{
$this
->
setData
(
$data
)
;
}
/**
* Destructor
*
@postcondition
ensures all Constraint object are deleted
*/
public
function
__destruct
(
)
{
$this
->
reset
(
)
;
}
/** ACTION METHODS **/
/**
* Cleans the Data by running through the Constraints
*
@precondition
!isChecked()
*
@return
bool
*
@throws
Gumbo_Exception
*/
public
function
clean
(
)
{
if
(
$this
->
isChecked
(
))
{
return
$this
->
isClean
(
)
;
}
$success
=
true
;
if
(
$this
->
toRunThru
(
))
{
foreach
(
$this
->
getConstraints
(
)
as
$key
=>
$obj
)
{
try
{
$tmp
=
$obj
->
test
(
$this
->
getData
(
))
;
if
(
$this
->
_constraints_return
[
$key
]
)
{
$this
->
setCleanData
(
$tmp
)
;
}
}
catch
(
Gumbo_Exception
$e
)
{
gumbo_trigger
(
$e
)
;
$success
=
false
;
}
}
}
else
{
try
{
foreach
(
$this
->
getConstraints
(
)
as
$key
=>
$obj
)
{
$tmp
=
$obj
->
test
(
$this
->
getData
(
))
;
if
(
$this
->
_constraints_return
[
$key
]
)
{
$this
->
setCleanData
(
$tmp
)
;
}
}
}
catch
(
Gumbo_Exception
$e
)
{
gumbo_trigger
(
$e
)
;
$success
=
false
;
}
}
$this
->
setClean
(
$success
)
;
$this
->
setChecked
(
true
)
;
return
$this
->
isClean
(
)
;
}
/**
* Adds a Constraint against the Data (additional arguments accepted for Constraint parameters)
*
@postcondition
!isChecked()
*
@postcondition
!isClean()
*
@param
Gumbo_Interface_Constraint
$obj
*/
public
function
addConstraint
(
Gumbo_Interface_Constraint
$obj
)
{
$this
->
_constraints
[
]
=
$obj
;
$this
->
_constraints_return
[
]
=
false
;
$this
->
setChecked
(
false
)
;
$this
->
setClean
(
false
)
;
}
/**
* Adds a return Constraint, which returns a formatted value
*
@postcondition
!isChecked()
*
@postcondition
!isClean()
*
@param
Gumbo_Interface_Constraint
$obj
*/
public
function
addReturnConstraint
(
Gumbo_Interface_Constraint
$obj
)
{
$this
->
_constraints
[
]
=
$obj
;
$this
->
_constraints_return
[
]
=
true
;
$this
->
setChecked
(
false
)
;
$this
->
setClean
(
false
)
;
}
/**
* Resets ALL Constraints
*
@postcondition
!getConstraints()
*
@postcondition
!isChecked()
*
@postcondition
!isClean()
*/
public
function
resetConstraints
(
)
{
$this
->
_constraints
=
array
(
)
;
$this
->
_constraints_return
;
$this
->
setChecked
(
false
)
;
$this
->
setClean
(
false
)
;
}
/** MUTATOR METHODS **/
/**
* Sets the input data
*
@postcondition
!isChecked()
*
@postcondition
!isClean()
*
@param
mixed
$data
*/
public
function
setData
(
$data
)
{
if
(
!
$this
->
getData
(
))
{
$this
->
_data_clean
=
$data
;
}
$this
->
_data_raw
=
$data
;
$this
->
setClean
(
false
)
;
$this
->
setChecked
(
false
)
;
}
/**
* Sets the Clean Data
*
@param
mixed
$data
*/
protected
function
setCleanData
(
$data
)
{
$this
->
_data_clean
=
$data
;
}
/**
* Sets if ALL Exceptions should be caught, or stop at first Exception
*
@param
bool
$val
*
@throws
Gumbo_Exception
*/
public
function
setRunThru
(
$val
)
{
try
{
if
(
!
is_bool
(
$val
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Argument
'
val
:
bool
' => {
$val
}
:
"
.
gettype
(
$val
))
;
}
$this
->
_run_thru
=
$val
;
}
catch
(
Gumbo_Exception
$e
)
{
$e
->
setFunction
(
__METHOD__
)
;
gumbo_trigger
(
$e
)
;
}
}
/**
* Sets the Data as Clean
*
@param
bool
$val
*
@throws
Gumbo_Exception
*/
protected
function
setClean
(
$val
)
{
try
{
if
(
!
is_bool
(
$val
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Argument
'
val
:
bool
' => {
$val
}
:
"
.
gettype
(
$val
))
;
}
$this
->
_clean
=
$val
;
}
catch
(
Gumbo_Exception
$e
)
{
$e
->
setFunction
(
__METHOD__
)
;
gumbo_trigger
(
$e
)
;
}
}
/**
* Sets the Data as Checked
*
@param
bool
$val
*
@throws
Gumbo_Exception
*/
protected
function
setChecked
(
$val
)
{
try
{
if
(
!
is_bool
(
$val
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Argument
'
val
:
bool
' => {
$val
}
:
"
.
gettype
(
$val
))
;
}
$this
->
_checked
=
$val
;
}
catch
(
Gumbo_Exception
$e
)
{
$e
->
setFunction
(
__METHOD__
)
;
gumbo_trigger
(
$e
)
;
}
}
/** ACCESSOR METHODS **/
/**
* Returns the Data
*
@param
bool
$raw
as raw data
*
@return
mixed
*
@throws
Gumbo_Exception
*/
public
function
getData
(
$raw
=
false
)
{
try
{
// verify precondition
if
(
!
is_bool
(
$raw
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Argument
'
raw
:
bool
' => {
$raw
}
:
"
.
gettype
(
$raw
))
;
}
}
catch
(
Gumbo_Exception
$e
)
{
$e
->
setFunction
(
__METHOD__
)
;
gumbo_trigger
(
$e
)
;
$raw
=
false
;
}
if
(
$raw
)
{
return
$this
->
_data_raw
;
}
return
$this
->
_data_clean
;
}
/**
* Returns ALL the Constraints
*
@return
Gumbo_Interface_Constraint[]
*/
public
function
getConstraints
(
)
{
return
$this
->
_constraints
;
}
/**
* Returns if the Data is clean
*
@return
bool
*/
public
function
isClean
(
)
{
return
$this
->
_clean
;
}
/**
* Returns if the Data was checked
*
@return
bool
*/
public
function
isChecked
(
)
{
return
$this
->
_checked
;
}
/**
* Returns if all Exceptions should be caught, or stop at first Exception
*
@return
bool
*/
public
function
toRunThru
(
)
{
return
$this
->
_run_thru
;
}
}
?>