eee
This commit is contained in:
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Kiri\Router\Validator;
|
namespace Kiri\Router\Validator;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Kiri\Router\Constrict\ConstrictRequest;
|
use Kiri\Router\Constrict\ConstrictRequest;
|
||||||
use Kiri\Router\Interface\ValidatorInterface;
|
use Kiri\Router\Interface\ValidatorInterface;
|
||||||
use Psr\Http\Message\RequestInterface;
|
use Psr\Http\Message\RequestInterface;
|
||||||
@@ -134,13 +135,14 @@ class Validator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($this->formData->{$name} != $value) {
|
if ($this->formData->{$name} != $value) {
|
||||||
throw new \Exception('Fail type value.');
|
throw new Exception('Fail type value.');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->formData->{$name} = match ($property->getName()) {
|
$this->formData->{$name} = match ($property->getName()) {
|
||||||
'int' => (int)$value,
|
'int' => (int)$value,
|
||||||
'float' => (float)$value,
|
'float' => (float)$value,
|
||||||
'bool' => $value == 'true',
|
'bool' => $value == 'true',
|
||||||
|
'array' => $this->arrayCheck($property, $name, $value),
|
||||||
default => $value
|
default => $value
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -149,6 +151,25 @@ class Validator
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ReflectionNamedType $property
|
||||||
|
* @param string $name
|
||||||
|
* @param string|array $value
|
||||||
|
* @return array
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
protected function arrayCheck(ReflectionNamedType $property, string $name, string|array $value): array
|
||||||
|
{
|
||||||
|
if (empty($value) || !is_array($value)) {
|
||||||
|
if ($property->allowsNull()) {
|
||||||
|
$this->formData->{$name} = null;
|
||||||
|
}
|
||||||
|
throw new Exception('TypeError Cannot assign string to property ' . $name . ' of type array');
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $field
|
* @param $field
|
||||||
* @return bool
|
* @return bool
|
||||||
|
|||||||
Reference in New Issue
Block a user