变更
This commit is contained in:
@@ -15,9 +15,8 @@ abstract class AbstractRequestMethod
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param string $formValidate
|
|
||||||
*/
|
*/
|
||||||
public function __construct(readonly public string $path, public string $formValidate = '')
|
public function __construct(readonly public string $path)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,30 +40,6 @@ abstract class AbstractRequestMethod
|
|||||||
|
|
||||||
$middlewareManager->set($class::class, $method, $instance->middleware);
|
$middlewareManager->set($class::class, $method, $instance->middleware);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->formValidate !== '') {
|
|
||||||
$middlewareManager->set($class::class, $method, ValidatorMiddleware::class, [$this->getFormRule()]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Validator|null
|
|
||||||
* @throws ReflectionException
|
|
||||||
*/
|
|
||||||
public function getFormRule(): ?Validator
|
|
||||||
{
|
|
||||||
$validator = new Validator();
|
|
||||||
$reflect = \Kiri::getDi()->getReflectionClass($this->formValidate);
|
|
||||||
$model = $reflect->newInstanceWithoutConstructor();
|
|
||||||
foreach ($reflect->getProperties() as $property) {
|
|
||||||
foreach ($property->getAttributes() as $attribute) {
|
|
||||||
$rule = $attribute->newInstance();
|
|
||||||
if ($rule instanceof ValidatorInterface) {
|
|
||||||
$validator->addRule($property->getName(), $model, $rule);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $validator;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user