background image

 

/** 
* ConcreteCommand. 
*/

 

class

 MoreThanZeroValidator 

implements

 Validator 

public

 

function

 isValid(

$value

return

 

$value

 > 0; 



 

/** 
* ConcreteCommand. 
*/

 

class

 EvenValidator 

implements

 Validator 

public

 

function

 isValid(

$value

return

 

$value

 % 2 == 0; 



 

/** 
* The Invoker. An implementation could store more than one 
* Validator if needed. 
*/

 

class

 ArrayProcessor 

protected

 

$_rule

 

public

 

function

 __construct (Validator 

$rule

$this

->_rule = 

$rule


 

public

 

function

 process(

array

 

$numbers

foreach

 (

$numbers

 

as

 

$n

) {