| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 | 
							- <?php
 
- declare (strict_types = 1);
 
- namespace app;
 
- use think\App;
 
- use think\exception\ValidateException;
 
- use think\Validate;
 
- abstract class BaseController
 
- {
 
-     
 
-     protected $request;
 
-     
 
-     protected $app;
 
-     
 
-     protected $batchValidate = false;
 
-     
 
-     protected $middleware = [];
 
-     
 
-     public function __construct(App $app)
 
-     {
 
-         $this->app     = $app;
 
-         $this->request = $this->app->request;
 
-         
 
-         $this->initialize();
 
-     }
 
-     
 
-     protected function initialize()
 
-     {}
 
-     
 
-     protected function validate(array $data, $validate, array $message = [], bool $batch = false)
 
-     {
 
-         if (is_array($validate)) {
 
-             $v = new Validate();
 
-             $v->rule($validate);
 
-         } else {
 
-             if (strpos($validate, '.')) {
 
-                 
 
-                 [$validate, $scene] = explode('.', $validate);
 
-             }
 
-             $class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
 
-             $v     = new $class();
 
-             if (!empty($scene)) {
 
-                 $v->scene($scene);
 
-             }
 
-         }
 
-         $v->message($message);
 
-         
 
-         if ($batch || $this->batchValidate) {
 
-             $v->batch(true);
 
-         }
 
-         return $v->failException(true)->check($data);
 
-     }
 
- }
 
 
  |