0 follower

Final Class Yiisoft\Hydrator\Attribute\Parameter\LeftTrimResolver

InheritanceYiisoft\Hydrator\Attribute\Parameter\LeftTrimResolver
ImplementsYiisoft\Hydrator\Attribute\Parameter\ParameterAttributeResolverInterface

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string|null $characters null )
$characters string|null

                public function __construct(
    private readonly ?string $characters = null,
) {
}

            
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 LeftTrim) {
        throw new UnexpectedAttributeException(LeftTrim::class, $attribute);
    }
    if (!$context->isResolved()) {
        return Result::fail();
    }
    $resolvedValue = $context->getResolvedValue();
    if (!is_string($resolvedValue)) {
        return Result::fail();
    }
    $characters = $attribute->characters ?? $this->characters;
    return Result::success(
        $characters === null ? ltrim($resolvedValue) : ltrim($resolvedValue, $characters)
    );
}