rendered paste bodyclass dataValidator
{
/*
* Variable: $strategy
* **
* @access private
* @var NULL
*/
var $strategy;
/*
* Method: dataValidator (constructor)
* **
* Notes: instantiates selected data validation constructor.
*
* Class inspired by devshed article "Introducing the Strategy Pattern"
* by Alejandro Gervasio.
*
* **
* @author Amgine
* @param $strategy string, validation strategy name.
* @return Null
*/
function dataValidator ( $strategy )
{
switch ( $strategy )
{
case 'alpha':
$this->strategy = new StrategyAlpha();
break;
case 'pathfile':
$this->strategy = new StrategyPathFile();
break;
case 'USPostal':
$this->strategy = new StrategyUSPostal();
break;
default:
trigger_error( 'Script: Invalid parameter for validation strategy. dataValidator.class.php::dataValidator::__constructor', E_USER_WARNING);
}
}
/*
* Method: validate
* **
* Notes: tests data.
* **
* @author Amgine
* @param $data
* @return bool, true = valid data
*/
function validate ( $data )
{
return $this->strategy->validateData( $data );
}
}