-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from emonkak/redesign-pagination
Redesign pagination
- Loading branch information
Showing
21 changed files
with
591 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Emonkak\Orm\Pagination; | ||
|
||
use Emonkak\Enumerable\EnumerableExtensions; | ||
|
||
/** | ||
* @template T | ||
* @implements \IteratorAggregate<T> | ||
* @implements PageInterface<T> | ||
*/ | ||
abstract class AbstractPage implements \IteratorAggregate, PageInterface | ||
{ | ||
/** | ||
* @use EnumerableExtensions<T> | ||
*/ | ||
use EnumerableExtensions; | ||
|
||
public function getOffset(): int | ||
{ | ||
return $this->getIndex() * $this->getPerPage(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function forward(): iterable | ||
{ | ||
$page = $this; | ||
|
||
yield $page; | ||
|
||
while ($page->hasNext()) { | ||
$page = $page->next(); | ||
|
||
yield $page; | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function backward(): iterable | ||
{ | ||
$page = $this; | ||
|
||
yield $page; | ||
|
||
while ($page->hasPrevious()) { | ||
$page = $page->previous(); | ||
|
||
yield $page; | ||
} | ||
} | ||
|
||
public function isFirst(): bool | ||
{ | ||
return !$this->hasPrevious(); | ||
} | ||
|
||
public function isLast(): bool | ||
{ | ||
return !$this->hasNext(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Emonkak\Orm\Pagination; | ||
|
||
/** | ||
* @template T | ||
* @extends PageInterface<T> | ||
* @method self<T> next() | ||
* @method self<T> previous() | ||
* @method iterable<self<T>> forward() | ||
* @method iterable<self<T>> backward() | ||
*/ | ||
interface PaginatablePageInterface extends PageInterface | ||
{ | ||
/** | ||
* @psalm-return PaginatorInterface<T> | ||
*/ | ||
public function getPaginator(): PaginatorInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.