Final Class Yiisoft\Data\Reader\Iterable\IterableDataReader
| Inheritance | Yiisoft\Data\Reader\Iterable\IterableDataReader |
|---|---|
| Implements | Yiisoft\Data\Reader\DataReaderInterface |
Iterable data reader takes iterable data as a source and can:
- Limit items read
- Skip N items from the beginning
- Sort items
- Form a filter criteria with Yiisoft\Data\Reader\FilterInterface
- Post-filter items with Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface
Public Methods
Method Details
| public __construct( iterable $data, Yiisoft\Data\Reader\Iterable\ValueReader\ValueReaderInterface $valueReader = new FlatValueReader(), Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface[] $extraFilterHandlers = [] ): mixed | ||
| $data | iterable |
Data to iterate. |
| $valueReader | Yiisoft\Data\Reader\Iterable\ValueReader\ValueReaderInterface | |
| $extraFilterHandlers | Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface[] | |
public function __construct(
private readonly iterable $data,
ValueReaderInterface $valueReader = new FlatValueReader(),
array $extraFilterHandlers = [],
) {
$filterHandlers = $this->prepareFilterHandlers([
new AllHandler(),
new NoneHandler(),
new AndXHandler(),
new OrXHandler(),
new BetweenHandler(),
new EqualsHandler(),
new EqualsNullHandler(),
new GreaterThanHandler(),
new GreaterThanOrEqualHandler(),
new InHandler(),
new LessThanHandler(),
new LessThanOrEqualHandler(),
new LikeHandler(),
new NotHandler(),
...$extraFilterHandlers,
]);
$this->context = new Context($filterHandlers, $valueReader);
$this->filter = new All();
}
| public count( ): integer |
public function count(): int
{
return count($this->internalRead(useLimitAndOffset: false));
}
| public getFilter( ): Yiisoft\Data\Reader\FilterInterface |
public function getFilter(): FilterInterface
{
return $this->filter;
}
| public getIterator( ): Generator |
public function getIterator(): Generator
{
yield from $this->read();
}
| public getSort( ): Yiisoft\Data\Reader\Sort|null |
public function getSort(): ?Sort
{
return $this->sort;
}
| public read( ): array |
public function read(): array
{
return $this->internalRead(useLimitAndOffset: true);
}
| public readOne( ): array|object|null |
public function readOne(): array|object|null
{
if ($this->limit === 0) {
return null;
}
/** @infection-ignore-all Any value more than one in `withLimit()` will be ignored because returned `current()` */
return $this
->withLimit(1)
->getIterator()
->current();
}
| public withFilter( Yiisoft\Data\Reader\FilterInterface $filter ): Yiisoft\Data\Reader\Iterable\IterableDataReader | ||
| $filter | Yiisoft\Data\Reader\FilterInterface | |
public function withFilter(FilterInterface $filter): static
{
$new = clone $this;
$new->filter = $filter;
return $new;
}
| public withLimit( integer|null $limit ): Yiisoft\Data\Reader\Iterable\IterableDataReader | ||
| $limit | integer|null | |
public function withLimit(?int $limit): static
{
if ($limit < 0) {
throw new InvalidArgumentException('The limit must not be less than 0.');
}
$new = clone $this;
$new->limit = $limit;
return $new;
}
| public withOffset( integer $offset ): Yiisoft\Data\Reader\Iterable\IterableDataReader | ||
| $offset | integer | |
public function withOffset(int $offset): static
{
$new = clone $this;
$new->offset = $offset;
return $new;
}
| public withSort( Yiisoft\Data\Reader\Sort|null $sort ): Yiisoft\Data\Reader\Iterable\IterableDataReader | ||
| $sort | Yiisoft\Data\Reader\Sort|null | |
public function withSort(?Sort $sort): static
{
$new = clone $this;
$new->sort = $sort;
return $new;
}
Signup or Login in order to comment.