1 | <?php |
||
15 | abstract class BaseRule |
||
16 | { |
||
17 | const CONFIG_ALL = 'all'; |
||
18 | const CONFIG_DATA = 'data'; |
||
19 | const CONFIG_FIELD_RULES = 'fieldRules'; |
||
20 | |||
21 | /** |
||
22 | * @var array $config |
||
23 | */ |
||
24 | private $config; |
||
25 | |||
26 | /** |
||
27 | * @var array $params |
||
28 | */ |
||
29 | private $params; |
||
30 | |||
31 | /** |
||
32 | * @var ValidationProviderInterface $validationProvider |
||
33 | */ |
||
34 | private $validationProvider; |
||
35 | |||
36 | /** |
||
37 | * BaseRule constructor. |
||
38 | * |
||
39 | * @param $config |
||
40 | */ |
||
41 | public function __construct( |
||
48 | |||
49 | /** |
||
50 | * Validator calls captured and remapped here. |
||
51 | * |
||
52 | * @return BaseRule Validator rule object. |
||
53 | */ |
||
54 | public function __call($method, array $params = array()) |
||
65 | |||
66 | /** |
||
67 | * Run rule against validator. |
||
68 | */ |
||
69 | private function buildRule($ruleName, $arguments = []) |
||
73 | |||
74 | /** |
||
75 | * Validate rule against value provided. |
||
76 | * We can control which method is called on the external library. |
||
77 | */ |
||
78 | public function validate($value) |
||
82 | |||
83 | /** |
||
84 | * Returns all config array, or specific one. |
||
85 | * |
||
86 | * @param string $type |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | public function getConfig($type = self::CONFIG_ALL) |
||
98 | |||
99 | /** |
||
100 | * If field has specific rule. |
||
101 | * |
||
102 | * @param string $rule |
||
103 | * |
||
104 | * @return bool |
||
105 | */ |
||
106 | public function hasRule($rule) |
||
110 | |||
111 | /** |
||
112 | * Check if variable is not required - to prevent error messages from another validators. |
||
113 | * |
||
114 | * @param string $type | 'var' or 'file' |
||
115 | * |
||
116 | * @return bool |
||
117 | */ |
||
118 | protected function isNotRequiredAndEmpty($type = 'var') |
||
133 | |||
134 | /** |
||
135 | * Set params to validator. |
||
136 | * |
||
137 | * @param $params |
||
138 | * |
||
139 | * @return $this |
||
140 | */ |
||
141 | public function setParams($params) |
||
147 | |||
148 | /** |
||
149 | * Returns params. |
||
150 | * |
||
151 | * @return mixed |
||
152 | */ |
||
153 | public function getParams() |
||
157 | |||
158 | /** |
||
159 | * Returns pure class name. |
||
160 | * |
||
161 | * @return string |
||
162 | */ |
||
163 | public function getRuleName() |
||
169 | |||
170 | /** |
||
171 | * Returns error message from rule. |
||
172 | * |
||
173 | * @return string |
||
174 | */ |
||
175 | abstract public function getMessage(); |
||
176 | |||
177 | /** |
||
178 | * The main function that validates the inputted value against |
||
179 | * an existing one or similar. |
||
180 | * |
||
181 | * @return bool Return a if values were valid/matched or not |
||
182 | */ |
||
183 | abstract public function isValid(); |
||
184 | } |
||
185 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.