@@ -27,6 +27,17 @@ class Request
2727
2828 protected static $ errors = [];
2929 protected static $ formDataMediaTypes = ['application/x-www-form-urlencoded ' ];
30+
31+ /**
32+ * Internal instance of Leaf Form
33+ * @var \Leaf\Form
34+ */
35+ protected static $ validator ;
36+
37+ public function __construct ()
38+ {
39+ static ::$ validator = new \Leaf \Form ;
40+ }
3041
3142 /**
3243 * Get HTTP method
@@ -333,7 +344,11 @@ public static function headers($key = null, bool $safeData = true)
333344 */
334345 public static function validate (array $ rules , bool $ returnFullData = false )
335346 {
336- $ data = \Leaf \Form::validate (static ::body (false ), $ rules );
347+ if (!static ::$ validator ) {
348+ static ::$ validator = new \Leaf \Form ;
349+ }
350+
351+ $ data = static ::$ validator ->validate (static ::body (false ), $ rules );
337352
338353 if ($ data === false ) {
339354 return false ;
@@ -342,6 +357,19 @@ public static function validate(array $rules, bool $returnFullData = false)
342357 return $ returnFullData ? $ data : static ::get (array_keys ($ rules ));
343358 }
344359
360+ /**
361+ * Return validator instance
362+ * @return \Leaf\Form
363+ */
364+ public static function validator ()
365+ {
366+ if (!static ::$ validator ) {
367+ static ::$ validator = new \Leaf \Form ;
368+ }
369+
370+ return static ::$ validator ;
371+ }
372+
345373 /**
346374 * Return the auth instance
347375 * @return \Leaf\Auth
@@ -409,7 +437,11 @@ public static function upload(string $key, string $destination, array $config =
409437 }
410438
411439 $ fileSystem = new \Leaf \FS ;
412- if (!isset ($ config ['rename ' ]) || !$ config ['rename ' ]) $ config ['unique ' ] = true ;
440+
441+ if (!isset ($ config ['rename ' ]) || !$ config ['rename ' ]) {
442+ $ config ['unique ' ] = true ;
443+ }
444+
413445 $ uploadedFile = $ fileSystem ->uploadFile (
414446 $ file ,
415447 preg_replace (
@@ -657,7 +689,7 @@ public static function errors()
657689 {
658690 return array_merge (
659691 static ::$ errors ,
660- \ Leaf \Form:: errors (),
692+ static :: $ validator ? static :: $ validator -> errors () : [] ,
661693 class_exists ('\Leaf\Auth ' ) ? static ::auth ()->errors () : []
662694 );
663695 }
0 commit comments