generated from cerbero90/skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
151 additions
and
16 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cerbero\LazyJsonPages\Exceptions; | ||
|
||
use Cerbero\LazyJsonPages\Paginations\Pagination; | ||
|
||
/** | ||
* The exception to throw when the given pagination is invalid. | ||
*/ | ||
class InvalidPaginationException extends LazyJsonPagesException | ||
{ | ||
/** | ||
* Instantiate the class. | ||
*/ | ||
public function __construct(public readonly string $class) | ||
{ | ||
$pagination = Pagination::class; | ||
|
||
parent::__construct("The class [{$class}] should extend [{$pagination}]."); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cerbero\LazyJsonPages\Paginations; | ||
|
||
use Cerbero\LazyJsonPages\Exceptions\InvalidPaginationException; | ||
use Traversable; | ||
|
||
/** | ||
* The user-defined pagination. | ||
*/ | ||
class CustomPagination extends LengthAwarePagination | ||
{ | ||
/** | ||
* Determine whether the configuration matches this pagination. | ||
*/ | ||
public function matches(): bool | ||
{ | ||
return $this->config->pagination !== null; | ||
} | ||
|
||
/** | ||
* Yield the paginated items. | ||
* | ||
* @return Traversable<int, mixed> | ||
*/ | ||
public function getIterator(): Traversable | ||
{ | ||
if (!is_subclass_of($this->config->pagination, Pagination::class)) { | ||
throw new InvalidPaginationException($this->config->pagination); | ||
} | ||
|
||
yield from new $this->config->pagination($this->source, $this->config); | ||
} | ||
} |
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