diff --git a/extend/Crud/Controller.php b/extend/Crud/Controller.php deleted file mode 100644 index e04e184..0000000 --- a/extend/Crud/Controller.php +++ /dev/null @@ -1,112 +0,0 @@ -initialize(); - } - - /** - * 初始化. - */ - protected function initialize() - { - } - - /** - * 验证数据. - * - * @param array $data 数据 - * @param array|string $validate 验证器名或者验证规则数组 - * @param array $message 提示信息 - * @param bool $batch 是否批量验证 - * - * @throws ValidateException - * - * @return array|string|true - */ - protected function validate(array $data, $validate, array $message = [], bool $batch = false) - { - if (is_array($validate)) { - $this->validate->rule($validate); - } else { - if (strpos($validate, '.')) { - // 支持场景 - [$validate, $scene] = explode('.', $validate); - } - $class = strpos($validate, '\\') !== false ? $validate : $this->app->parseClass('validate', $validate); - $this->validate = new $class(); - if (!empty($scene)) { - $this->validate->scene($scene); - } - } - - $this->validate->message($message); - - // 是否批量验证 - if ($batch || $this->batchValidate) { - $this->validate->batch(true); - } - - return $this->validate->failException(true)->check($data); - } -} diff --git a/extend/Crud/CrudController.php b/extend/Crud/CrudController.php index 1b64106..7931928 100644 --- a/extend/Crud/CrudController.php +++ b/extend/Crud/CrudController.php @@ -12,9 +12,7 @@ namespace Crud; -use TAnt\Abstracts\AbstractController; - -abstract class CrudController extends AbstractController +trait CrudController { public function index() { diff --git a/extend/TAnt/Command/Crud/stubs/controller.stub b/extend/TAnt/Command/Crud/stubs/controller.stub index a7b173d..d47bfda 100644 --- a/extend/TAnt/Command/Crud/stubs/controller.stub +++ b/extend/TAnt/Command/Crud/stubs/controller.stub @@ -16,8 +16,10 @@ use Crud\CrudController; use think\annotation\Inject; use app\common\service\{%service%}; -class {%className%} extends CrudController +class {%className%} { + use CrudController; + /** * @Inject * @var {%service%} @@ -25,9 +27,7 @@ class {%className%} extends CrudController protected $service; protected $validates = [ - 'create' => [ - ], - 'update' => [ - ] + 'create' => [], + 'update' => [] ]; }