Final Class Yiisoft\Hydrator\Attribute\Parameter\RightTrimResolver
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Resolver for {@see RightTrim} attribute.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| getParameterValue() | Yiisoft\ |
Method Details
| public mixed __construct ( string|null $characters = null, boolean $multibyte = false, string|null $encoding = null ) | ||
| $characters | string|null |
The list of characters to strip when it is not specified in the attribute.
With |
| $multibyte | boolean |
Whether to use multibyte-aware trimming when it is not specified in the attribute. |
| $encoding | string|null |
The encoding to use in multibyte mode when it is not specified in the attribute. |
public function __construct(
private readonly ?string $characters = null,
private readonly bool $multibyte = false,
private readonly ?string $encoding = null,
) {
TrimCharacters::checkMultibyteFunctionsExist($multibyte);
}
public function getParameterValue(
ParameterAttributeInterface $attribute,
ParameterAttributeResolveContext $context,
): Result {
if (!$attribute instanceof RightTrim) {
throw new UnexpectedAttributeException(RightTrim::class, $attribute);
}
if (!$context->isResolved()) {
return Result::fail();
}
$resolvedValue = $context->getResolvedValue();
if (!is_string($resolvedValue)) {
return Result::fail();
}
$characters = $attribute->characters ?? $this->characters;
$multibyte = $attribute->multibyte ?? $this->multibyte;
$encoding = $attribute->encoding ?? $this->encoding;
TrimCharacters::checkDeprecatedRanges($characters, $multibyte, $encoding);
if (!$multibyte) {
return Result::success(
$characters === null ? rtrim($resolvedValue) : rtrim($resolvedValue, $characters),
);
}
return Result::success(
mb_rtrim(
$resolvedValue,
$characters === null ? null : TrimCharacters::expandRanges($characters, $encoding),
$encoding,
),
);
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.