0 follower

Final Class Yiisoft\Data\Reader\Iterable\IterableDataReader

InheritanceYiisoft\Data\Reader\Iterable\IterableDataReader
ImplementsYiisoft\Data\Reader\DataReaderInterface

Iterable data reader takes iterable data as a source and can:

Method Details

Hide inherited methods

__construct() public method

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();
}

            
count() public method

public count( ): integer

                public function count(): int
{
    return count($this->internalRead(useLimitAndOffset: false));
}

            
getFilter() public method

public getFilter( ): Yiisoft\Data\Reader\FilterInterface

                public function getFilter(): FilterInterface
{
    return $this->filter;
}

            
getIterator() public method

public getIterator( ): Generator

                public function getIterator(): Generator
{
    yield from $this->read();
}

            
getLimit() public method

public getLimit( ): integer|null

                public function getLimit(): ?int
{
    return $this->limit;
}

            
getOffset() public method

public getOffset( ): integer

                public function getOffset(): int
{
    return $this->offset;
}

            
getSort() public method

public getSort( ): Yiisoft\Data\Reader\Sort|null

                public function getSort(): ?Sort
{
    return $this->sort;
}

            
read() public method

public read( ): array

                public function read(): array
{
    return $this->internalRead(useLimitAndOffset: true);
}

            
readOne() public method

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();
}

            
withFilter() public method

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;
}

            
withLimit() public method

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;
}

            
withOffset() public method

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;
}

            
withSort() public method

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;
}