1 | <?php |
||
7 | class RuleFactory |
||
8 | { |
||
9 | /** |
||
10 | * Validator map allows for flexibility when creating a validation rule |
||
11 | * You can use 'required' instead of 'required' for the name of the rule |
||
12 | * or 'minLength'/'minlength' instead of 'MinLength' |
||
13 | * |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $validatorsMap = array(); |
||
17 | |||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $errorMessages = array(); |
||
22 | |||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $labeledErrorMessages = array(); |
||
27 | |||
28 | /** |
||
29 | * Constructor |
||
30 | */ |
||
31 | 27 | public function __construct() |
|
35 | |||
36 | /** |
||
37 | * Set up the default rules that come with the library |
||
38 | */ |
||
39 | 27 | protected function registerDefaultRules() |
|
97 | |||
98 | |||
99 | /** |
||
100 | * Register a class to be used when creating validation rules |
||
101 | * |
||
102 | * @param string $name |
||
103 | * @param string $class |
||
104 | * |
||
105 | * @return \Sirius\Validation\RuleFactory |
||
106 | */ |
||
107 | 27 | public function register($name, $class, $errorMessage = '', $labeledErrorMessage = '') |
|
121 | |||
122 | /** |
||
123 | * Factory method to construct a validator based on options that are used most of the times |
||
124 | * |
||
125 | * @param string|callable $name |
||
126 | * name of a validator class or a callable object/function |
||
127 | * @param string|array $options |
||
128 | * validator options (an array, JSON string or QUERY string) |
||
129 | * @param string $messageTemplate |
||
130 | * error message template |
||
131 | * @param string $label |
||
132 | * label of the form input field or model attribute |
||
133 | * |
||
134 | * @throws \InvalidArgumentException |
||
135 | * @return \Sirius\Validation\Rule\AbstractValidator |
||
136 | */ |
||
137 | 24 | public function createRule($name, $options = null, $messageTemplate = null, $label = null) |
|
155 | |||
156 | /** |
||
157 | * Set default error message for a rule |
||
158 | * |
||
159 | * @param string $rule |
||
160 | * @param string|null $messageWithoutLabel |
||
161 | * @param string|null $messageWithLabel |
||
162 | * |
||
163 | * @return $this |
||
164 | */ |
||
165 | public function setMessages($rule, $messageWithoutLabel = null, $messageWithLabel = null) |
||
176 | |||
177 | /** |
||
178 | * Get the error message saved in the registry for a rule, where the message |
||
179 | * is with or without a the label |
||
180 | * |
||
181 | * @param string $name name of the rule |
||
182 | * @param bool $withLabel |
||
183 | * |
||
184 | * @return string|NULL |
||
185 | */ |
||
186 | 19 | protected function getSuggestedMessageTemplate($name, $withLabel) |
|
197 | |||
198 | /** |
||
199 | * @param $name |
||
200 | * @param $options |
||
201 | * |
||
202 | * @return CallbackRule |
||
203 | */ |
||
204 | 24 | protected function construcRuleByNameAndOptions($name, $options) |
|
237 | } |
||
238 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: