eee
This commit is contained in:
+35
-35
@@ -13,45 +13,45 @@ class BindForm implements InjectParameterInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param string $formValidate
|
||||
*/
|
||||
public function __construct(readonly public string $formValidate)
|
||||
{
|
||||
}
|
||||
/**
|
||||
* @param string $formValidate
|
||||
*/
|
||||
public function __construct(readonly public string $formValidate)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string $method
|
||||
* @return mixed
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function dispatch(string $class, string $method): mixed
|
||||
{
|
||||
$validator = new Validator();
|
||||
$reflect = \Kiri::getDi()->getReflectionClass($this->formValidate);
|
||||
$validator->setFormData($reflect->newInstanceWithoutConstructor());
|
||||
foreach ($reflect->getProperties() as $property) {
|
||||
foreach ($property->getAttributes() as $attribute) {
|
||||
if (!class_exists($attribute->getName())) {
|
||||
continue;
|
||||
}
|
||||
$rule = $attribute->newInstance();
|
||||
if ($rule instanceof ValidatorInterface) {
|
||||
$validator->addRule($property->getName(), $rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string $method
|
||||
* @return mixed
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function dispatch(string $class, string $method): object
|
||||
{
|
||||
$validator = new Validator();
|
||||
$reflect = \Kiri::getDi()->getReflectionClass($this->formValidate);
|
||||
$validator->setFormData($reflect->newInstanceWithoutConstructor());
|
||||
foreach ($reflect->getProperties() as $property) {
|
||||
foreach ($property->getAttributes() as $attribute) {
|
||||
if (!class_exists($attribute->getName())) {
|
||||
continue;
|
||||
}
|
||||
$rule = $attribute->newInstance();
|
||||
if ($rule instanceof ValidatorInterface) {
|
||||
$validator->addRule($property->getName(), $rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$middleware = new ValidatorMiddleware();
|
||||
$middleware->validator = $validator;
|
||||
$middleware = new ValidatorMiddleware();
|
||||
$middleware->validator = $validator;
|
||||
|
||||
$manager = \Kiri::getDi()->get(Middleware::class);
|
||||
$manager->set($class, $method, $middleware);
|
||||
$manager = \Kiri::getDi()->get(Middleware::class);
|
||||
$manager->set($class, $method, $middleware);
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator->getFormData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user