1 | <?php |
||
37 | class Rule |
||
38 | { |
||
39 | /** |
||
40 | * @var Validator |
||
41 | */ |
||
42 | public $validator = false; |
||
43 | private $_matcher; |
||
44 | private $_options; |
||
45 | private $_enabled = true; |
||
46 | |||
47 | /** |
||
48 | * @param MatcherInterface|null $matcher |
||
49 | * @param array $options |
||
50 | * |
||
51 | * @throws \InvalidArgumentException |
||
52 | */ |
||
53 | 98 | public function __construct(MatcherInterface $matcher = null, array $options = []) |
|
75 | |||
76 | 43 | public function setContext($context) |
|
77 | { |
||
78 | 43 | if (is_array($context)) { |
|
79 | 5 | $this->validator = new Validator($context); |
|
80 | 43 | } elseif (is_callable($context)) { |
|
81 | 1 | $this->validator = new DelegateValidator($context); |
|
82 | 40 | } elseif ($context instanceof Validator) { |
|
83 | 38 | $this->validator = $context; |
|
84 | 38 | } else { |
|
85 | 1 | throw new \InvalidArgumentException('$context must be valid Validator'); |
|
86 | } |
||
87 | 42 | } |
|
88 | |||
89 | 2 | public function getMatcher() |
|
93 | |||
94 | 1 | public function setMatcher(MatcherInterface $matcher) |
|
95 | { |
||
96 | 1 | $this->_matcher = $matcher; |
|
97 | 1 | } |
|
98 | |||
99 | /** |
||
100 | * @param $source |
||
101 | * |
||
102 | * @return Token[]|\Iterator |
||
103 | */ |
||
104 | 24 | public function match($source) |
|
108 | |||
109 | 97 | public function __get($option) |
|
113 | |||
114 | 19 | public function __set($option, $value) |
|
118 | |||
119 | 1 | public function enable() |
|
120 | { |
||
123 | |||
124 | 1 | public function disable() |
|
128 | } |
||
129 |