Final Class Yiisoft\Data\Reader\Iterable\FilterHandler\LikeHandler
| Inheritance | Yiisoft\Data\Reader\Iterable\FilterHandler\LikeHandler |
|---|---|
| Implements | Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface |
Like iterable filter handler ensures that the field value is like-match to a given value (case-sensitive).
Public Methods
| Method | Description | Defined By |
|---|---|---|
| getFilterClass() | Yiisoft\Data\Reader\Iterable\FilterHandler\LikeHandler | |
| match() | Yiisoft\Data\Reader\Iterable\FilterHandler\LikeHandler |
Method Details
| public boolean match ( object|array $item, Yiisoft\Data\Reader\FilterInterface $filter, Yiisoft\Data\Reader\Iterable\Context $context ) | ||
| $item | object|array | |
| $filter | Yiisoft\Data\Reader\FilterInterface | |
| $context | Yiisoft\Data\Reader\Iterable\Context | |
public function match(object|array $item, FilterInterface $filter, Context $context): bool
{
/** @var Like $filter */
$itemValue = $context->readValue($item, $filter->field);
if (!is_string($itemValue)) {
return false;
}
$searchValue = (string) $filter->value;
if ($searchValue === '') {
return true;
}
return match ($filter->mode) {
LikeMode::Contains => $this->matchContains($itemValue, $searchValue, $filter->caseSensitive),
LikeMode::StartsWith => $this->matchStartsWith($itemValue, $searchValue, $filter->caseSensitive),
LikeMode::EndsWith => $this->matchEndsWith($itemValue, $searchValue, $filter->caseSensitive),
};
}
Signup or Login in order to comment.