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