1: <?php
2:
3: /**
4: * Jyxo PHP Library
5: *
6: * LICENSE
7: *
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: * https://github.com/jyxo/php/blob/master/license.txt
12: */
13:
14: /**
15: * Checks if the given value is from an array of predefined values.
16: *
17: * @category Jyxo
18: * @package Jyxo_Input
19: * @subpackage Validator
20: * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
21: * @license https://github.com/jyxo/php/blob/master/license.txt
22: * @author Jakub Tománek
23: */
24: class Jyxo_Input_Validator_InArray extends Jyxo_Input_Validator_AbstractValidator
25: {
26: /**
27: * Array of allowed values.
28: *
29: * @var array
30: */
31: private $allowed = array();
32:
33: /**
34: * Constructor.
35: *
36: * @param array $allowed Array of allowed values
37: */
38: public function __construct(array $allowed)
39: {
40: $this->allowed = $allowed;
41: }
42:
43: /**
44: * Validates a value.
45: *
46: * @param mixed $value Input value
47: * @return boolean
48: */
49: public function isValid($value)
50: {
51: return in_array($value, $this->allowed);
52: }
53: }
54: