8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
17 * @package Zend_Validate
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
25 * @see Zend_Validate_Abstract
27 require_once 'Zend/Validate/Abstract.php';
32 * @package Zend_Validate
33 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
34 * @license http://framework.zend.com/license/new-bsd New BSD License
36 class Zend_Validate_InArray
extends Zend_Validate_Abstract
39 const NOT_IN_ARRAY
= 'notInArray';
44 protected $_messageTemplates = array(
45 self
::NOT_IN_ARRAY
=> "'%value%' was not found in the haystack"
49 * Haystack of possible values
56 * Whether a strict in_array() invocation is used
63 * Sets validator options
65 * @param array $haystack
66 * @param boolean $strict
69 public function __construct(array $haystack, $strict = false)
71 $this->setHaystack($haystack)
76 * Returns the haystack option
80 public function getHaystack()
82 return $this->_haystack
;
86 * Sets the haystack option
88 * @param mixed $haystack
89 * @return Zend_Validate_InArray Provides a fluent interface
91 public function setHaystack(array $haystack)
93 $this->_haystack
= $haystack;
98 * Returns the strict option
102 public function getStrict()
104 return $this->_strict
;
108 * Sets the strict option
110 * @param boolean $strict
111 * @return Zend_Validate_InArray Provides a fluent interface
113 public function setStrict($strict)
115 $this->_strict
= $strict;
120 * Defined by Zend_Validate_Interface
122 * Returns true if and only if $value is contained in the haystack option. If the strict
123 * option is true, then the type of $value is also checked.
125 * @param mixed $value
128 public function isValid($value)
130 $this->_setValue($value);
131 if (!in_array($value, $this->_haystack
, $this->_strict
)) {