1: <?php
2:
3: /**
4: * Copyright 2015, Eduardo Trujillo
5: *
6: * For the full copyright and license information, please view the LICENSE
7: * file that was distributed with this source code.
8: *
9: * This file is part of the Nucleus package
10: */
11:
12: namespace Chromabits\Nucleus\Meditation\Constraints;
13:
14: /**
15: * Class InArrayConstraint.
16: *
17: * @author Eduardo Trujillo <ed@chromabits.com>
18: * @package Chromabits\Nucleus\Meditation\Constraints
19: */
20: class InArrayConstraint extends AbstractConstraint
21: {
22: /**
23: * @var array
24: */
25: protected $allowed;
26:
27: /**
28: * @return array
29: */
30: public function getAllowed()
31: {
32: return $this->allowed;
33: }
34:
35: /**
36: * Construct an instance of a InArrayConstraint.
37: *
38: * @param array $allowed
39: */
40: public function __construct(array $allowed)
41: {
42: parent::__construct();
43:
44: $this->allowed = $allowed;
45: }
46:
47: /**
48: * Check if the constraint is met.
49: *
50: * @param mixed $value
51: * @param array $context
52: *
53: * @return mixed
54: */
55: public function check($value, array $context = [])
56: {
57: return in_array($value, $this->allowed, true);
58: }
59:
60: /**
61: * Get string representation of this constraint.
62: *
63: * @return mixed
64: */
65: public function toString()
66: {
67: return 'InArrayConstraint';
68: }
69: }
70: