Final Class Yiisoft\Hydrator\Validator\Attribute\ValidateResolver
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Resolver for {@see Validate} attribute.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| getParameterValue() | Yiisoft\ |
|
| setResult() | Sets validation result. | Yiisoft\ |
Method Details
| public mixed __construct ( \ | ||
| $validator | \ |
Validator to use. |
public function __construct(
private ValidatorInterface $validator,
) {}
| public \ | ||
| $attribute | \ |
|
| $context | \ |
|
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();
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.