Final Class Yiisoft\Hydrator\Attribute\Parameter\LeftTrimResolver
| Inheritance | Yiisoft\Hydrator\Attribute\Parameter\LeftTrimResolver |
|---|---|
| Implements | Yiisoft\Hydrator\Attribute\Parameter\ParameterAttributeResolverInterface |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Hydrator\Attribute\Parameter\LeftTrimResolver | |
| getParameterValue() | Yiisoft\Hydrator\Attribute\Parameter\LeftTrimResolver |
Method Details
| public mixed __construct ( string|null $characters = null ) | ||
| $characters | string|null | |
public function __construct(
private readonly ?string $characters = null,
) {
}
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)
);
}
Signup or Login in order to comment.