0 follower

Final Class Yiisoft\Hydrator\Attribute\Parameter\CollectionResolver

InheritanceYiisoft\Hydrator\Attribute\Parameter\CollectionResolver
ImplementsYiisoft\Hydrator\Attribute\Parameter\ParameterAttributeResolverInterface

Method Details

Hide inherited methods

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 Collection) {
        throw new UnexpectedAttributeException(Collection::class, $attribute);
    }
    if (!$context->isResolved()) {
        return Result::fail();
    }
    $resolvedValue = $context->getResolvedValue();
    if (!is_iterable($resolvedValue)) {
        return Result::fail();
    }
    if (is_a($attribute->className, BackedEnum::class, true)) {
        /**
         * @psalm-suppress ArgumentTypeCoercion Because class name is backed enumeration name.
         */
        $collection = $this->createCollectionOfBackedEnums($resolvedValue, $attribute->className);
    } else {
        $collection = $this->createCollectionOfObjects(
            $resolvedValue,
            $context->getHydrator(),
            $attribute->className
        );
    }
    return Result::success($collection);
}