8 Commits

Author SHA1 Message Date
as2252258 0b3c22d7b9 eee 2026-06-12 23:57:20 +08:00
as2252258 835bc747c4 eee 2025-07-14 15:35:04 +08:00
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
2 changed files with 9 additions and 5 deletions
+8 -4
View File
@@ -6,6 +6,7 @@ namespace validator;
use Database\ModelInterface;
use Exception;
use Kiri;
/**
@@ -15,6 +16,7 @@ use Kiri;
class Validator extends BaseValidator
{
/**
* classMap
*/
@@ -42,6 +44,7 @@ class Validator extends BaseValidator
'round' => ['class' => RoundValidator::class,],
];
/** @var BaseValidator[] */
private ?array $validators = [];
@@ -51,6 +54,7 @@ class Validator extends BaseValidator
* @param array $fields
* @param array $rules
* @return $this
* @throws Exception
*/
public function make(ModelInterface $model, array $fields, array $rules): static
{
@@ -72,10 +76,11 @@ class Validator extends BaseValidator
/**
* @param ModelInterface $model
* @param $field
* @param $key
* @param $val
* @return array
* @throws
* @throws Exception
*/
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
*/
public function validation(ModelInterface $model): bool
public function validation(array $attributes): bool
{
if (count($this->validators) < 1) {
return true;
}
$attributes = $model->getChanges();
foreach ($attributes as $field => $attribute) {
if (isset($this->validators[$field])) {
$validator = $this->validators[$field];
+1 -1
View File
@@ -9,7 +9,7 @@
],
"license": "MIT",
"require": {
"php": ">=8.0",
"php": ">=8.5",
"ext-json": "*",
"ext-pdo": "*"
},