0 follower

Final Class Yiisoft\Hydrator\Validator\Attribute\ValidateResolver

InheritanceYiisoft\Hydrator\Validator\Attribute\ValidateResolver
ImplementsYiisoft\Hydrator\Attribute\Parameter\ParameterAttributeResolverInterface

Resolver for {@see Validate} attribute.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Yiisoft\Validator\ValidatorInterface $validator )
$validator \Yiisoft\Validator\ValidatorInterface

Validator to use.

                public function __construct(
    private ValidatorInterface $validator,
) {
}

            
getParameterValue() public method

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();
}

            
setResult() public method

Sets validation result.

public void setResult ( \Yiisoft\Validator\Result|null $result )
$result \Yiisoft\Validator\Result|null

Validation result.

                public function setResult(?ValidationResult $result): void
{
    $this->result = $result;
}