1 | <?php |
||
5 | trait JavascriptRulesTrait |
||
6 | { |
||
7 | /** |
||
8 | * Handles multidimensional attribute names. |
||
9 | * |
||
10 | * @param string $attribute |
||
11 | * |
||
12 | * @return string |
||
13 | */ |
||
14 | abstract protected function getAttributeName($attribute); |
||
15 | |||
16 | /** |
||
17 | * Confirmed rule is applied to confirmed attribute. |
||
18 | * |
||
19 | * @param $attribute |
||
20 | * @param array $parameters |
||
21 | * |
||
22 | * @return array |
||
23 | */ |
||
24 | 1 | protected function ruleConfirmed($attribute, array $parameters) |
|
25 | { |
||
26 | 1 | $parameters[0] = $this->getAttributeName($attribute); |
|
27 | 1 | $attribute = "{$attribute}_confirmation"; |
|
28 | |||
29 | 1 | return [$attribute, $parameters]; |
|
30 | } |
||
31 | |||
32 | /** |
||
33 | * Returns Javascript parameters for After rule. |
||
34 | * |
||
35 | * @param $attribute |
||
36 | * @param array $parameters |
||
37 | * |
||
38 | * @return array |
||
39 | */ |
||
40 | 4 | protected function ruleAfter($attribute, array $parameters) |
|
41 | { |
||
42 | 4 | if (! ($date = strtotime($parameters[0]))) { |
|
43 | 2 | $date = $this->getAttributeName($parameters[0]); |
|
44 | } |
||
45 | |||
46 | 4 | return [$attribute, [$date]]; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * Returns Javascript parameters for Before rule. |
||
51 | * |
||
52 | * @param $attribute |
||
53 | * @param array $parameters |
||
54 | * |
||
55 | * @return array |
||
56 | */ |
||
57 | 2 | protected function ruleBefore($attribute, array $parameters) |
|
61 | |||
62 | /** |
||
63 | * Validate that two attributes match. |
||
64 | * |
||
65 | * @param string $attribute |
||
66 | * @param array $parameters |
||
67 | * |
||
68 | * @return array |
||
69 | */ |
||
70 | 2 | protected function ruleSame($attribute, array $parameters) |
|
76 | |||
77 | /** |
||
78 | * Validate that an attribute is different from another attribute. |
||
79 | * |
||
80 | * @param string $attribute |
||
81 | * @param array $parameters |
||
82 | * |
||
83 | * @return array |
||
84 | */ |
||
85 | 1 | protected function ruleDifferent($attribute, array $parameters) |
|
89 | |||
90 | /** |
||
91 | * Validate that an attribute exists when any other attribute exists. |
||
92 | * |
||
93 | * @param string $attribute |
||
94 | * @param mixed $parameters |
||
95 | * |
||
96 | * @return array |
||
97 | */ |
||
98 | 4 | protected function ruleRequiredWith($attribute, array $parameters) |
|
104 | |||
105 | /** |
||
106 | * Validate that an attribute exists when all other attributes exists. |
||
107 | * |
||
108 | * @param string $attribute |
||
109 | * @param mixed $parameters |
||
110 | * |
||
111 | * @return array |
||
112 | */ |
||
113 | 1 | protected function ruleRequiredWithAll($attribute, array $parameters) |
|
117 | |||
118 | /** |
||
119 | * Validate that an attribute exists when another attribute does not. |
||
120 | * |
||
121 | * @param string $attribute |
||
122 | * @param mixed $parameters |
||
123 | * |
||
124 | * @return array |
||
125 | */ |
||
126 | 1 | protected function ruleRequiredWithout($attribute, array $parameters) |
|
130 | |||
131 | /** |
||
132 | * Validate that an attribute exists when all other attributes do not. |
||
133 | * |
||
134 | * @param string $attribute |
||
135 | * @param mixed $parameters |
||
136 | * |
||
137 | * @return array |
||
138 | */ |
||
139 | 1 | protected function ruleRequiredWithoutAll($attribute, array $parameters) |
|
143 | |||
144 | /** |
||
145 | * Validate that an attribute exists when another attribute has a given value. |
||
146 | * |
||
147 | * @param string $attribute |
||
148 | * @param mixed $parameters |
||
149 | * |
||
150 | * @return array |
||
151 | */ |
||
152 | 3 | protected function ruleRequiredIf($attribute, array $parameters) |
|
158 | |||
159 | /** |
||
160 | * Validate that an attribute exists when another attribute does not have a given value. |
||
161 | * |
||
162 | * @param string $attribute |
||
163 | * @param mixed $parameters |
||
164 | * |
||
165 | * @return array |
||
166 | */ |
||
167 | 1 | protected function ruleRequiredUnless($attribute, array $parameters) |
|
171 | } |
||
172 |