6 Commits

Author SHA1 Message Date
as2252258 1e9156600a eee 2024-04-15 15:38:13 +08:00
as2252258 0a744f4209 eee 2024-04-15 15:36:13 +08:00
as2252258 4454cdd772 eee 2024-04-15 15:34:13 +08:00
as2252258 a6c8800de5 eee 2024-04-15 15:27:43 +08:00
as2252258 b9fd81238d eee 2024-03-01 14:46:50 +08:00
as2252258 2c554e765c eee 2024-01-10 17:35:55 +08:00
+8 -4
View File
@@ -6,6 +6,7 @@ namespace validator;
use Database\ModelInterface; use Database\ModelInterface;
use Exception;
use Kiri; use Kiri;
/** /**
@@ -15,6 +16,7 @@ use Kiri;
class Validator extends BaseValidator class Validator extends BaseValidator
{ {
/** /**
* classMap * classMap
*/ */
@@ -42,6 +44,7 @@ class Validator extends BaseValidator
'round' => ['class' => RoundValidator::class,], 'round' => ['class' => RoundValidator::class,],
]; ];
/** @var BaseValidator[] */ /** @var BaseValidator[] */
private ?array $validators = []; private ?array $validators = [];
@@ -51,6 +54,7 @@ class Validator extends BaseValidator
* @param array $fields * @param array $fields
* @param array $rules * @param array $rules
* @return $this * @return $this
* @throws Exception
*/ */
public function make(ModelInterface $model, array $fields, array $rules): static public function make(ModelInterface $model, array $fields, array $rules): static
{ {
@@ -72,10 +76,11 @@ class Validator extends BaseValidator
/** /**
* @param ModelInterface $model * @param ModelInterface $model
* @param $field
* @param $key * @param $key
* @param $val * @param $val
* @return array * @return array
* @throws * @throws Exception
*/ */
protected function mapGen(ModelInterface $model, $field, $key, $val): array protected function mapGen(ModelInterface $model, $field, $key, $val): array
{ {
@@ -94,15 +99,14 @@ class Validator extends BaseValidator
/** /**
* @param ModelInterface $model * @param array $attributes
* @return bool * @return bool
*/ */
public function validation(ModelInterface $model): bool public function validation(array $attributes): bool
{ {
if (count($this->validators) < 1) { if (count($this->validators) < 1) {
return true; return true;
} }
$attributes = $model->getChanges();
foreach ($attributes as $field => $attribute) { foreach ($attributes as $field => $attribute) {
if (isset($this->validators[$field])) { if (isset($this->validators[$field])) {
$validator = $this->validators[$field]; $validator = $this->validators[$field];