Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0b3c22d7b9 | |||
| 835bc747c4 | |||
| 1e9156600a | |||
| 0a744f4209 | |||
| 4454cdd772 | |||
| a6c8800de5 | |||
| b9fd81238d | |||
| 2c554e765c |
+8
-4
@@ -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
@@ -9,7 +9,7 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": ">=8.0",
|
||||
"php": ">=8.5",
|
||||
"ext-json": "*",
|
||||
"ext-pdo": "*"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user