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 | 29 | public function __construct() |
|
35 | |||
36 | /** |
||
37 | * Set up the default rules that come with the library |
||
38 | */ |
||
39 | 29 | protected function registerDefaultRules() |
|
100 | |||
101 | |||
102 | /** |
||
103 | * Register a class to be used when creating validation rules |
||
104 | * |
||
105 | * @param string $name |
||
106 | * @param string $class |
||
107 | * |
||
108 | * @return \Sirius\Validation\RuleFactory |
||
109 | */ |
||
110 | 29 | public function register($name, $class, $errorMessage = '', $labeledErrorMessage = '') |
|
124 | |||
125 | /** |
||
126 | * Factory method to construct a validator based on options that are used most of the times |
||
127 | * |
||
128 | * @param string|callable $name |
||
129 | * name of a validator class or a callable object/function |
||
130 | * @param string|array $options |
||
131 | * validator options (an array, JSON string or QUERY string) |
||
132 | * @param string $messageTemplate |
||
133 | * error message template |
||
134 | * @param string $label |
||
135 | * label of the form input field or model attribute |
||
136 | * |
||
137 | * @throws \InvalidArgumentException |
||
138 | * @return \Sirius\Validation\Rule\AbstractValidator |
||
139 | */ |
||
140 | 26 | public function createRule($name, $options = null, $messageTemplate = null, $label = null) |
|
158 | |||
159 | /** |
||
160 | * Set default error message for a rule |
||
161 | * |
||
162 | * @param string $rule |
||
163 | * @param string|null $messageWithoutLabel |
||
164 | * @param string|null $messageWithLabel |
||
165 | * |
||
166 | * @return $this |
||
167 | */ |
||
168 | public function setMessages($rule, $messageWithoutLabel = null, $messageWithLabel = null) |
||
179 | |||
180 | /** |
||
181 | * Get the error message saved in the registry for a rule, where the message |
||
182 | * is with or without a the label |
||
183 | * |
||
184 | * @param string $name name of the rule |
||
185 | * @param bool $withLabel |
||
186 | * |
||
187 | * @return string|NULL |
||
188 | */ |
||
189 | 21 | protected function getSuggestedMessageTemplate($name, $withLabel) |
|
200 | |||
201 | /** |
||
202 | * @param $name |
||
203 | * @param $options |
||
204 | * |
||
205 | * @return CallbackRule |
||
206 | */ |
||
207 | 26 | protected function construcRuleByNameAndOptions($name, $options) |
|
240 | } |
||
241 |
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: