00001 <?php 00002 00027 require_once 'Zend/Validate/Abstract.php'; 00028 00029 00036 class Zend_Validate_InArray extends Zend_Validate_Abstract 00037 { 00038 00039 const NOT_IN_ARRAY = 'notInArray'; 00040 00044 protected $_messageTemplates = array( 00045 self::NOT_IN_ARRAY => "'%value%' was not found in the haystack" 00046 ); 00047 00053 protected $_haystack; 00054 00060 protected $_strict; 00061 00069 public function __construct(array $haystack, $strict = false) 00070 { 00071 $this->setHaystack($haystack) 00072 ->setStrict($strict); 00073 } 00074 00080 public function getHaystack() 00081 { 00082 return $this->_haystack; 00083 } 00084 00091 public function setHaystack(array $haystack) 00092 { 00093 $this->_haystack = $haystack; 00094 return $this; 00095 } 00096 00102 public function getStrict() 00103 { 00104 return $this->_strict; 00105 } 00106 00113 public function setStrict($strict) 00114 { 00115 $this->_strict = $strict; 00116 return $this; 00117 } 00118 00128 public function isValid($value) 00129 { 00130 $this->_setValue($value); 00131 if (!in_array($value, $this->_haystack, $this->_strict)) { 00132 $this->_error(self::NOT_IN_ARRAY); 00133 return false; 00134 } 00135 return true; 00136 } 00137 00138 }