From 9b34de060bf8a64311f2ce1347dc6dda44f669d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 29 Sep 2021 11:16:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Base/Model.php | 15 +++++++++++---- src/Model.php | 8 -------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Base/Model.php b/src/Base/Model.php index f9fd276..37a6218 100644 --- a/src/Base/Model.php +++ b/src/Base/Model.php @@ -24,6 +24,7 @@ use Database\HasOne; use Database\ModelInterface; use Database\Mysql\Columns; use Database\Relation; +use Database\SqlBuilder; use Database\Traits\HasBase; use Exception; use JetBrains\PhpStorm\Pure; @@ -97,6 +98,12 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T protected string $connection = 'db'; + /** + * @var array + */ + protected array $rules = []; + + /** * @var Relation|null */ @@ -183,7 +190,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T /** * @param $data - * @return ModelInterface + * @return Model */ public function setWith($data): static { @@ -620,7 +627,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T if (!is_null($data)) { $this->_attributes = merge($this->_attributes, $data); } - if (!$this->validator($this->rules()) || !$this->beforeSave($this)) { + if (!$this->validator($this->rules) || !$this->beforeSave($this)) { return false; } [$change, $condition, $fields] = $this->separation(); @@ -632,11 +639,11 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T /** - * @param array $rule + * @param array|null $rule * @return bool * @throws Exception */ - public function validator(array $rule): bool + public function validator(?array $rule): bool { if (empty($rule)) return true; $validate = $this->resolve($rule); diff --git a/src/Model.php b/src/Model.php index 3344ab5..e8b61af 100644 --- a/src/Model.php +++ b/src/Model.php @@ -32,14 +32,6 @@ class Model extends Base\Model { - /** - * @return array - */ - public function rules(): array - { - return []; - } - /** * @param string $column * @param int $value