Skip to content

Commit

Permalink
Implement interface. (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed May 1, 2023
1 parent 826deb6 commit 64cfa21
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -11,6 +11,7 @@
"prefer-stable": true,
"require": {
"php": "^8.1",
"yii-tools/interface": "^1.0@dev",
"yiisoft/active-record": "^3.0@dev",
"yiisoft/db": "^1.0"
},
Expand Down
16 changes: 9 additions & 7 deletions src/ActiveIteratorProvider.php
Expand Up @@ -8,14 +8,16 @@
use Countable;
use IteratorAggregate;
use Traversable;
use Yii\Interface\LimitInterface;
use Yii\Interface\OffsetInterface;
use Yiisoft\ActiveRecord\ActiveQueryInterface;

/**
* Provides a way to iterate over the results of an Active Query with support for pagination.
*
* @implements IteratorAggregate<int, array>
*/
final class ActiveIteratorProvider implements IteratorAggregate, Countable
final class ActiveIteratorProvider implements IteratorAggregate, Countable, LimitInterface, OffsetInterface
{
private int $limit = 0;
private int $offset = 0;
Expand Down Expand Up @@ -67,25 +69,25 @@ public function readOne(): array
/**
* Returns a new instance specifying the number of items to be returned per page.
*
* @param int $limit The number of items to be returned per page.
* @param int $value The number of items to be returned per page.
*/
public function withLimit(int $limit): static
public function withLimit(int $value): static
{
$new = clone $this;
$new->limit = $limit;
$new->limit = $value;

return $new;
}

/**
* Returns a new instance specifying the number of items to be skipped before starting to return items.
*
* @param int $offset The number of items to be skipped before starting to return items.
* @param int $value The number of items to be skipped before starting to return items.
*/
public function withOffset(int $offset): static
public function withOffset(int $value): static
{
$new = clone $this;
$new->offset = $offset;
$new->offset = $value;

return $new;
}
Expand Down
16 changes: 9 additions & 7 deletions src/ArrayIteratorProvider.php
Expand Up @@ -8,6 +8,8 @@
use Countable;
use IteratorAggregate;
use Traversable;
use Yii\Interface\LimitInterface;
use Yii\Interface\OffsetInterface;

use function array_slice;
use function count;
Expand All @@ -17,7 +19,7 @@
*
* @implements IteratorAggregate<int, array>
*/
final class ArrayIteratorProvider implements IteratorAggregate, Countable
final class ArrayIteratorProvider implements IteratorAggregate, Countable, LimitInterface, OffsetInterface
{
private int|null $limit = 0;
private int $offset = 0;
Expand Down Expand Up @@ -69,25 +71,25 @@ public function readOne(): array
/**
* Returns a new instance specifying the number of items to be returned per page.
*
* @param int|null $limit The number of items to be returned per page.
* @param int|null $value The number of items to be returned per page.
*/
public function withLimit(int|null $limit): static
public function withLimit(int|null $value): static
{
$new = clone $this;
$new->limit = $limit;
$new->limit = $value;

return $new;
}

/**
* Returns a new instance specifying the number of items to be skipped before starting to return items.
*
* @param int $offset The number of items to be skipped before starting to return items.
* @param int $value The number of items to be skipped before starting to return items.
*/
public function withOffset(int $offset): static
public function withOffset(int $value): static
{
$new = clone $this;
$new->offset = $offset;
$new->offset = $value;

return $new;
}
Expand Down
16 changes: 9 additions & 7 deletions src/SqlIteratorDataProvider.php
Expand Up @@ -8,6 +8,8 @@
use Countable;
use IteratorAggregate;
use Traversable;
use Yii\Interface\LimitInterface;
use Yii\Interface\OffsetInterface;
use Yiisoft\Db\Connection\ConnectionInterface;

use function count;
Expand All @@ -17,7 +19,7 @@
*
* @implements IteratorAggregate<int, array>
*/
final class SqlIteratorDataProvider implements IteratorAggregate, Countable
final class SqlIteratorDataProvider implements IteratorAggregate, Countable, LimitInterface, OffsetInterface
{
private int $limit = 0;
private int $offset = 0;
Expand Down Expand Up @@ -66,25 +68,25 @@ public function readOne(): array
/**
* Returns a new instance specifying the number of items to be returned per page.
*
* @param int $limit The number of items to be returned per page.
* @param int $value The number of items to be returned per page.
*/
public function withLimit(int $limit): static
public function withLimit(int $value): static
{
$new = clone $this;
$new->limit = $limit;
$new->limit = $value;

return $new;
}

/**
* Returns a new instance specifying the number of items to be skipped before starting to return items.
*
* @param int $offset The number of items to be skipped before starting to return items.
* @param int $value The number of items to be skipped before starting to return items.
*/
public function withOffset(int $offset): static
public function withOffset(int $value): static
{
$new = clone $this;
$new->offset = $offset;
$new->offset = $value;

return $new;
}
Expand Down

0 comments on commit 64cfa21

Please sign in to comment.