1 | <?php |
||
8 | class ValidatorHandler |
||
9 | { |
||
10 | use UseDelegatedValidatorTrait; |
||
11 | |||
12 | /** |
||
13 | * Rule used to disable validations. |
||
14 | * |
||
15 | * @const string |
||
16 | */ |
||
17 | const JSVALIDATION_DISABLE = 'NoJsValidation'; |
||
18 | |||
19 | /** |
||
20 | * @var RuleParser |
||
21 | */ |
||
22 | protected $rules; |
||
23 | /** |
||
24 | * @var MessageParser |
||
25 | */ |
||
26 | protected $messages; |
||
27 | |||
28 | /** |
||
29 | * @var bool |
||
30 | */ |
||
31 | protected $remote = true; |
||
32 | |||
33 | /** |
||
34 | * Create a new JsValidation instance. |
||
35 | * |
||
36 | * @param RuleParser $rules |
||
37 | * @param MessageParser $messages |
||
38 | */ |
||
39 | 120 | public function __construct(RuleParser $rules, MessageParser $messages) |
|
40 | { |
||
41 | 120 | $this->rules = $rules; |
|
42 | 120 | $this->messages = $messages; |
|
43 | 120 | $this->validator = $rules->getDelegatedValidator(); |
|
44 | 120 | } |
|
45 | |||
46 | /** |
||
47 | * Sets delegated Validator instance. |
||
48 | * |
||
49 | * @param \Proengsoft\JsValidation\Support\DelegatedValidator $validator |
||
50 | * @return void |
||
51 | */ |
||
52 | 48 | public function setDelegatedValidator(DelegatedValidator $validator) |
|
58 | |||
59 | /** |
||
60 | * Enable or disables remote validations. |
||
61 | * |
||
62 | * @param bool $enabled |
||
63 | * @return void |
||
64 | */ |
||
65 | 12 | public function setRemote($enabled) |
|
66 | { |
||
67 | 12 | $this->remote = $enabled; |
|
68 | 12 | } |
|
69 | |||
70 | /** |
||
71 | * Generate Javascript Validations. |
||
72 | * |
||
73 | * @return array |
||
74 | */ |
||
75 | 48 | protected function generateJavascriptValidations() |
|
90 | |||
91 | /** |
||
92 | * Make Laravel Validations compatible with JQuery Validation Plugin. |
||
93 | * |
||
94 | * @param $attribute |
||
95 | * @param $rules |
||
96 | * @param bool $includeRemote |
||
97 | * @return array |
||
98 | */ |
||
99 | 36 | protected function jsConvertRules($attribute, $rules, $includeRemote) |
|
118 | |||
119 | /** |
||
120 | * Check if rule should be validated with javascript. |
||
121 | * |
||
122 | * @param $jsRule |
||
123 | 36 | * @param bool $includeRemote |
|
124 | * @return bool |
||
125 | 36 | */ |
|
126 | protected function isValidatable($jsRule, $includeRemote) |
||
130 | |||
131 | /** |
||
132 | * Check if JS Validation is disabled for attribute. |
||
133 | * |
||
134 | 48 | * @param $attribute |
|
135 | * @return bool |
||
136 | 48 | */ |
|
137 | public function jsValidationEnabled($attribute) |
||
141 | |||
142 | /** |
||
143 | * Returns view data to render javascript. |
||
144 | 48 | * |
|
145 | * @return array |
||
146 | 48 | */ |
|
147 | 48 | public function validationData() |
|
157 | |||
158 | /** |
||
159 | * Validate Conditional Validations using Ajax in specified fields. |
||
160 | * |
||
161 | * @param string $attribute |
||
162 | 12 | * @param string|array $rules |
|
163 | * @return void |
||
164 | */ |
||
165 | public function sometimes($attribute, $rules = []) |
||
173 | } |
||
174 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.