12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- /**
- *
- * Cube Framework $Id$ gmd9ouS4xubtNXtVQIQIKYC/O5Fd1vw7CrUNuUkKDh4=
- *
- * @link http://codecu.be/framework
- * @copyright Copyright (c) 2014 CodeCube SRL
- * @license http://codecu.be/framework/license Commercial License
- *
- * @version 1.0
- */
- /**
- * in array validator class
- */
- namespace Cube\Validate;
- class InArray extends AbstractValidate
- {
- protected $_message = "'%s' was not found in the haystack.";
- /**
- *
- * array to compare the needle against
- *
- * @var array
- */
- protected $_haystack = array();
- /**
- *
- * class constructor
- *
- * initialize the haystack
- *
- * @param array $haystack
- */
- public function __construct(array $haystack = null)
- {
- if ($haystack !== null) {
- $this->setHaystack($haystack);
- }
- }
- /**
- *
- * get haystack
- *
- * @return bool
- */
- public function getHaystack()
- {
- return $this->_haystack;
- }
- /**
- *
- * set haystack
- *
- * @param array $haystack
- * @return \Cube\Validate\InArray
- */
- public function setHaystack(array $haystack)
- {
- $this->_haystack = $haystack;
- return $this;
- }
- /**
- *
- * checks if the variable is contained in the haystack submitted
- *
- * @return bool return true if the validation is successful
- */
- public function isValid()
- {
- if (!in_array($this->_value, $this->_haystack)) {
- return false;
- }
- return true;
- }
- }
|