改名
This commit is contained in:
+11
-4
@@ -24,6 +24,7 @@ use Database\HasOne;
|
|||||||
use Database\ModelInterface;
|
use Database\ModelInterface;
|
||||||
use Database\Mysql\Columns;
|
use Database\Mysql\Columns;
|
||||||
use Database\Relation;
|
use Database\Relation;
|
||||||
|
use Database\SqlBuilder;
|
||||||
use Database\Traits\HasBase;
|
use Database\Traits\HasBase;
|
||||||
use Exception;
|
use Exception;
|
||||||
use JetBrains\PhpStorm\Pure;
|
use JetBrains\PhpStorm\Pure;
|
||||||
@@ -97,6 +98,12 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
|
|||||||
protected string $connection = 'db';
|
protected string $connection = 'db';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected array $rules = [];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Relation|null
|
* @var Relation|null
|
||||||
*/
|
*/
|
||||||
@@ -183,7 +190,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $data
|
* @param $data
|
||||||
* @return ModelInterface
|
* @return Model
|
||||||
*/
|
*/
|
||||||
public function setWith($data): static
|
public function setWith($data): static
|
||||||
{
|
{
|
||||||
@@ -620,7 +627,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
|
|||||||
if (!is_null($data)) {
|
if (!is_null($data)) {
|
||||||
$this->_attributes = merge($this->_attributes, $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;
|
return false;
|
||||||
}
|
}
|
||||||
[$change, $condition, $fields] = $this->separation();
|
[$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
|
* @return bool
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function validator(array $rule): bool
|
public function validator(?array $rule): bool
|
||||||
{
|
{
|
||||||
if (empty($rule)) return true;
|
if (empty($rule)) return true;
|
||||||
$validate = $this->resolve($rule);
|
$validate = $this->resolve($rule);
|
||||||
|
|||||||
@@ -32,14 +32,6 @@ class Model extends Base\Model
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function rules(): array
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $column
|
* @param string $column
|
||||||
* @param int $value
|
* @param int $value
|
||||||
|
|||||||
Reference in New Issue
Block a user