1- <?php
2- namespace LaravelArdent \Laravalid \Converter \Base ;
1+ <?php namespace LaravelArdent \Laravalid \Converter \Base ;
32
43use LaravelArdent \Laravalid \Helper ;
54
65/**
76 * Base converter class for converter plugins
8- *
97 * @package Laravel Validation For Client-Side
108 * @author Bilal Gultekin <[email protected] > 119 * @license MIT
@@ -16,42 +14,36 @@ abstract class Converter
1614
1715 /**
1816 * Rule converter class instance
19- *
2017 * @var array
2118 */
2219 protected static $ rule ;
2320
2421 /**
2522 * Message converter class instance
26- *
2723 * @var array
2824 */
2925 protected static $ message ;
3026
3127 /**
3228 * Route redirecter class instance
33- *
3429 * @var array
3530 */
3631 protected static $ route ;
3732
3833 /**
3934 * Rules which specify input type is numeric
40- *
4135 * @var array
4236 */
4337 protected $ validationRules = [];
4438
4539 /**
4640 * Current form name
47- *
4841 * @var string
4942 */
5043 protected $ currentFormName = null ;
5144
5245 /**
5346 * Rules which specify input type is numeric
54- *
5547 * @var array
5648 */
5749 protected $ numericRules = ['integer ' , 'numeric ' ];
@@ -80,9 +72,7 @@ public function route()
8072
8173 /**
8274 * Set rules for validation
83- *
8475 * @param array $rules Laravel validation rules
85- *
8676 */
8777 public function set ($ rules , $ formName = null )
8878 {
@@ -95,7 +85,6 @@ public function set($rules, $formName = null)
9585
9686 /**
9787 * Reset validation rules
98- *
9988 */
10089 public function reset ()
10190 {
@@ -110,9 +99,7 @@ public function reset()
11099
111100 /**
112101 * Set form name in order to get related validation rules
113- *
114102 * @param array $formName Form name
115- *
116103 */
117104 public function setFormName ($ formName )
118105 {
@@ -121,9 +108,7 @@ public function setFormName($formName)
121108
122109 /**
123110 * Get all given validation rules
124- *
125111 * @param array $rules Laravel validation rules
126- *
127112 */
128113 public function getValidationRules ()
129114 {
@@ -140,18 +125,17 @@ public function getValidationRules()
140125
141126 /**
142127 * Returns validation rules for given input name
143- *
144- * @return string
128+ * @return array
145129 */
146- protected function getValidationRule ($ inputName )
130+ public function getValidationRule ($ inputName )
147131 {
148- return is_array ($ this ->getValidationRules ()[$ inputName ])? $ this ->getValidationRules ()[$ inputName ] :
132+ return is_array ($ this ->getValidationRules ()[$ inputName ])?
133+ $ this ->getValidationRules ()[$ inputName ] :
149134 explode ('| ' , $ this ->getValidationRules ()[$ inputName ]);
150135 }
151136
152137 /**
153138 * Checks if there is a rules for given input name
154- *
155139 * @return string
156140 */
157141 protected function checkValidationRule ($ inputName )
@@ -161,7 +145,8 @@ protected function checkValidationRule($inputName)
161145
162146 public function convert ($ inputName )
163147 {
164- $ outputAttributes = [];
148+ $ outputAttributes = [];
149+ $ messageAttributes = [];
165150
166151 if ($ this ->checkValidationRule ($ inputName ) === false ) {
167152 return [];
@@ -171,14 +156,17 @@ public function convert($inputName)
171156 $ type = $ this ->getTypeOfInput ($ rules );
172157
173158 foreach ($ rules as $ rule ) {
174- $ parsedRule = $ this ->parseValidationRule ($ rule );
175- $ outputAttributes =
176- $ outputAttributes + $ this ->rule ()->convert ($ parsedRule ['name ' ], [$ parsedRule , $ inputName , $ type ]);
159+ $ parsedRule = $ this ->parseValidationRule ($ rule );
160+ $ ruleAttributes = $ this ->rule ()->convert ($ parsedRule ['name ' ], [$ parsedRule , $ inputName , $ type ]);
161+ $ outputAttributes += $ ruleAttributes ;
162+
163+ if (in_array ($ parsedRule ['name ' ], ['max ' , 'between ' ])) {
164+ $ outputAttributes ['maxlength ' ] = $ ruleAttributes ['data-rule-maxlength ' ];
165+ }
177166
178167 if (\Config::get ('laravalid.useLaravelMessages ' , true )) {
179168 $ messageAttributes = $ this ->message ()->convert ($ parsedRule ['name ' ], [$ parsedRule , $ inputName , $ type ]);
180169
181- // if empty message attributes
182170 if (empty ($ messageAttributes )) {
183171 $ messageAttributes = $ this ->getDefaultErrorMessage ($ parsedRule ['name ' ], $ inputName );
184172 }
@@ -191,9 +179,7 @@ public function convert($inputName)
191179 }
192180
193181 /**
194- * Get all rules and return type of input if rule specifies type
195- * Now, just for numeric
196- *
182+ * Gets all rules and returns type of input if rule specifies type. Now, just for numeric.
197183 * @return string
198184 */
199185 protected function getTypeOfInput ($ rulesOfInput )
@@ -211,8 +197,7 @@ protected function getTypeOfInput($rulesOfInput)
211197 }
212198
213199 /**
214- * Parses validition rule of laravel
215- *
200+ * Parses validation rule of laravel
216201 * @return array
217202 */
218203 protected function parseValidationRule ($ rule )
@@ -228,7 +213,6 @@ protected function parseValidationRule($rule)
228213
229214 /**
230215 * Gets default error message
231- *
232216 * @return string
233217 */
234218 protected function getDefaultErrorMessage ($ laravelRule , $ attribute )
0 commit comments