eee
This commit is contained in:
+41
-14
@@ -3,6 +3,8 @@
|
|||||||
namespace Kiri\Router\Validator;
|
namespace Kiri\Router\Validator;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Kiri\Di\Inject\Config;
|
||||||
|
use Kiri\Di\Inject\Container;
|
||||||
use Kiri\Di\Interface\InjectParameterInterface;
|
use Kiri\Di\Interface\InjectParameterInterface;
|
||||||
use Kiri\Router\Base\Middleware;
|
use Kiri\Router\Base\Middleware;
|
||||||
use Kiri\Router\Validator\RequestFilter\RequestFilterInterface;
|
use Kiri\Router\Validator\RequestFilter\RequestFilterInterface;
|
||||||
@@ -15,6 +17,7 @@ use Kiri\Router\Validator\Types\StringProxy;
|
|||||||
use Kiri\Router\Validator\Types\TypesProxy;
|
use Kiri\Router\Validator\Types\TypesProxy;
|
||||||
use Kiri\Server\ServerInterface;
|
use Kiri\Server\ServerInterface;
|
||||||
use ReflectionNamedType;
|
use ReflectionNamedType;
|
||||||
|
use ReflectionProperty;
|
||||||
use ReflectionUnionType;
|
use ReflectionUnionType;
|
||||||
use function inject;
|
use function inject;
|
||||||
|
|
||||||
@@ -50,17 +53,7 @@ class BindForm implements InjectParameterInterface
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$binding = $property->getAttributes(Binding::class);
|
$this->properties($validator, $property, $object);
|
||||||
if (count($binding) == 1) {
|
|
||||||
/** @var Binding $rule */
|
|
||||||
$rule = $binding[0]->newInstance();
|
|
||||||
|
|
||||||
$validator->addRule($property->getName(), $rule->dispatch($object, $property->getName()));
|
|
||||||
$validator->setAlias($property->getName(), $rule->field);
|
|
||||||
}
|
|
||||||
|
|
||||||
$typeProxy = $this->_typeValidator($property);
|
|
||||||
$validator->addRule($property->getName(), [$typeProxy, false]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$middleware = \instance(ValidatorMiddleware::class);
|
$middleware = \instance(ValidatorMiddleware::class);
|
||||||
@@ -72,11 +65,45 @@ class BindForm implements InjectParameterInterface
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \ReflectionProperty $property
|
* @param Validator $validator
|
||||||
* @return object
|
* @param ReflectionProperty $property
|
||||||
|
* @param object $object
|
||||||
|
* @return void
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function _typeValidator(\ReflectionProperty $property): TypesProxy
|
protected function properties(Validator $validator, ReflectionProperty $property, object $object)
|
||||||
|
{
|
||||||
|
$propertyContainer = $property->getAttributes(Container::class);
|
||||||
|
if (count($propertyContainer) > 0) {
|
||||||
|
($propertyContainer[0]->newInstance())->dispatch($object, $property->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$propertyConfig = $property->getAttributes(Config::class);
|
||||||
|
if (count($propertyConfig) > 0) {
|
||||||
|
($propertyConfig[0]->newInstance())->dispatch($object, $property->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
$binding = $property->getAttributes(Binding::class);
|
||||||
|
if (count($binding) > 0) {
|
||||||
|
/** @var Binding $rule */
|
||||||
|
$rule = $binding[0]->newInstance();
|
||||||
|
|
||||||
|
$validator->addRule($property->getName(), $rule->dispatch($object, $property->getName()));
|
||||||
|
$validator->setAlias($property->getName(), $rule->field);
|
||||||
|
}
|
||||||
|
|
||||||
|
$typeProxy = $this->_typeValidator($property);
|
||||||
|
$validator->addRule($property->getName(), [$typeProxy, false]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ReflectionProperty $property
|
||||||
|
* @return TypesProxy
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private function _typeValidator(ReflectionProperty $property): TypesProxy
|
||||||
{
|
{
|
||||||
$getType = $property->getType();
|
$getType = $property->getType();
|
||||||
if (is_null($getType)) {
|
if (is_null($getType)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user