Final Class Yiisoft\Hydrator\Validator\Attribute\ValidateResolver
| Inheritance | Yiisoft\Hydrator\Validator\Attribute\ValidateResolver |
|---|---|
| Implements | Yiisoft\Hydrator\Attribute\Parameter\ParameterAttributeResolverInterface |
Resolver for {@see Validate} attribute.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Hydrator\Validator\Attribute\ValidateResolver | |
| getParameterValue() | Yiisoft\Hydrator\Validator\Attribute\ValidateResolver | |
| setResult() | Sets validation result. | Yiisoft\Hydrator\Validator\Attribute\ValidateResolver |
Method Details
| public mixed __construct ( \Yiisoft\Validator\ValidatorInterface $validator ) | ||
| $validator | \Yiisoft\Validator\ValidatorInterface |
Validator to use. |
public function __construct(
private ValidatorInterface $validator,
) {
}
| public \Yiisoft\Hydrator\Result getParameterValue ( \Yiisoft\Hydrator\Attribute\Parameter\ParameterAttributeInterface $attribute, \Yiisoft\Hydrator\AttributeHandling\ParameterAttributeResolveContext $context ) | ||
| $attribute | \Yiisoft\Hydrator\Attribute\Parameter\ParameterAttributeInterface | |
| $context | \Yiisoft\Hydrator\AttributeHandling\ParameterAttributeResolveContext | |
public function getParameterValue(
ParameterAttributeInterface $attribute,
ParameterAttributeResolveContext $context,
): Result {
if (!$attribute instanceof Validate) {
throw new UnexpectedAttributeException(Validate::class, $attribute);
}
if ($this->result !== null) {
$parameterName = $context->getParameter()->getName();
$result = $this->validator->validate(
$context->isResolved() ? [$parameterName => $context->getResolvedValue()] : [],
[$parameterName => $attribute->getRules()],
);
foreach ($result->getErrors() as $error) {
$this->result->addError(
$error->getMessage(),
$error->getParameters(),
$error->getValuePath(),
);
}
}
return Result::fail();
}
Signup or Login in order to comment.