eee
This commit is contained in:
+19
-4
@@ -510,6 +510,18 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getChanges(): array
|
||||||
|
{
|
||||||
|
if (!$this->isNewExample) {
|
||||||
|
return \array_uintersect_assoc($this->_oldAttributes, $this->_attributes);
|
||||||
|
}
|
||||||
|
return $this->_attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param $value
|
||||||
* @return $this
|
* @return $this
|
||||||
@@ -534,7 +546,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
$validate = $this->resolve($rule);
|
$validate = $this->resolve($rule);
|
||||||
if (!$validate->validation()) {
|
if (!$validate->validation($this)) {
|
||||||
return \Kiri::getLogger()->failure($validate->getError(), 'mysql');
|
return \Kiri::getLogger()->failure($validate->getError(), 'mysql');
|
||||||
} else {
|
} else {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -548,11 +560,14 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
|
|||||||
*/
|
*/
|
||||||
private function resolve($rule): Validator
|
private function resolve($rule): Validator
|
||||||
{
|
{
|
||||||
$validate = Validator::instance($this->_attributes, $this);
|
$validate = new Validator();
|
||||||
foreach ($rule as $val) {
|
foreach ($rule as $val) {
|
||||||
$field = array_shift($val);
|
$field = array_shift($val);
|
||||||
|
if (is_string($field)) {
|
||||||
$validate->make($field, $val);
|
$validate->make($this, [$field], $val);
|
||||||
|
} else {
|
||||||
|
$validate->make($this, $field, $val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $validate;
|
return $validate;
|
||||||
}
|
}
|
||||||
|
|||||||
+65
-34
@@ -17,12 +17,12 @@ namespace Database;
|
|||||||
interface ModelInterface
|
interface ModelInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array|string|int $param
|
* @param array|string|int $param
|
||||||
* @param null $db
|
* @param null $db
|
||||||
* @return ModelInterface|null
|
* @return ModelInterface|null
|
||||||
*/
|
*/
|
||||||
public static function findOne(array|string|int $param, $db = NULL): ?static;
|
public static function findOne(array|string|int $param, $db = NULL): ?static;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,44 +31,75 @@ interface ModelInterface
|
|||||||
public function optimize(): mixed;
|
public function optimize(): mixed;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $param
|
* @param int $param
|
||||||
* @param null $db
|
* @param null $db
|
||||||
* @return ModelInterface|null
|
* @return ModelInterface|null
|
||||||
*/
|
*/
|
||||||
public static function primary(int $param, $db = NULL): ?static;
|
public static function primary(int $param, $db = NULL): ?static;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return static
|
* @return static
|
||||||
*/
|
*/
|
||||||
public static function populate(array $data): static;
|
public static function populate(array $data): static;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ActiveQuery
|
* @return ActiveQuery
|
||||||
* return a sql queryBuilder
|
* return a sql queryBuilder
|
||||||
*/
|
*/
|
||||||
public static function query(): ActiveQuery;
|
public static function query(): ActiveQuery;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ?string
|
* @return ?string
|
||||||
*/
|
*/
|
||||||
public function getPrimary(): ?string;
|
public function getPrimary(): ?string;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getTable(): string;
|
public function getTable(): string;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Connection
|
* @return Connection
|
||||||
*/
|
*/
|
||||||
public function getConnection(): Connection;
|
public function getConnection(): Connection;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $field
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getAttribute(string $field): mixed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $field
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getOldAttribute(string $field): mixed;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $field
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function setAttribute(string $field): mixed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $field
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function setOldAttribute(string $field): mixed;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getChanges(): array;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user