-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description ## Checklist - [x] Updated CHANGELOG files - [x] Updated Documentation - [x] Unit Tests Created - [x] php-cs-fixer
- Loading branch information
1 parent
40b9991
commit 2a37bd0
Showing
19 changed files
with
880 additions
and
10 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
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 |
---|---|---|
|
@@ -70,6 +70,10 @@ | |
"path": "src/SonsOfPHP/Component/Money", | ||
"repository": "[email protected]:SonsOfPHP/money.git" | ||
}, | ||
{ | ||
"path": "src/SonsOfPHP/Component/Pager", | ||
"repository": "[email protected]:SonsOfPHP/pager.git" | ||
}, | ||
{ | ||
"path": "src/SonsOfPHP/Component/Version", | ||
"repository": "[email protected]:SonsOfPHP/version.git" | ||
|
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,79 @@ | ||
--- | ||
title: Pager | ||
description: PHP Pager | ||
--- | ||
|
||
Simple yet powerful pagination | ||
|
||
## Installation | ||
|
||
```shell | ||
composer require sonsofphp/pager | ||
``` | ||
|
||
## Usage | ||
|
||
Basic Usage | ||
|
||
```php | ||
<?php | ||
|
||
use SonsOfPHP\Component\Pager\Adapter\ArrayAdapter; | ||
use SonsOfPHP\Component\Pager\Pager; | ||
|
||
$pager = new Pager(new ArrayAdapter($results)); | ||
|
||
foreach ($pager as $result) { | ||
// ... | ||
} | ||
``` | ||
|
||
Advance Usage | ||
|
||
```php | ||
<?php | ||
|
||
use SonsOfPHP\Component\Pager\Adapter\ArrayAdapter; | ||
use SonsOfPHP\Component\Pager\Pager; | ||
|
||
// These are the default option values | ||
$pager = new Pager(new ArrayAdapter($results), [ | ||
'current_page' => 1, | ||
'max_per_page' => 10, | ||
]); | ||
|
||
// You can also set current page and max per page | ||
$pager->setCurrentPage(1); | ||
$pager->setMaxPerPage(10); | ||
``` | ||
|
||
## Adapters | ||
|
||
### ArrayAdapter | ||
|
||
```php | ||
<?php | ||
|
||
use SonsOfPHP\Component\Pager\Adapter\ArrayAdapter; | ||
|
||
$adapter = new ArrayAdapter($results); | ||
``` | ||
|
||
### CallableAdabter | ||
|
||
Will take any `callable` arguments. | ||
|
||
```php | ||
<?php | ||
|
||
use SonsOfPHP\Component\Pager\Adapter\CallableAdapter; | ||
|
||
$adapter = new CallableAdapter( | ||
count: function (): int { | ||
// ... | ||
}, | ||
slice: function (int $offset, ?int $length): iterable { | ||
// ... | ||
}, | ||
); | ||
``` |
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,4 @@ | ||
/Tests export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore |
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,3 @@ | ||
composer.lock | ||
phpunit.xml | ||
vendor/ |
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SonsOfPHP\Component\Pager\Adapter; | ||
|
||
use SonsOfPHP\Contract\Pager\AdapterInterface; | ||
|
||
/** | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
class ArrayAdapter implements AdapterInterface | ||
{ | ||
public function __construct( | ||
private array $array, | ||
) {} | ||
|
||
public function count(): int | ||
{ | ||
return count($this->array); | ||
} | ||
|
||
public function getSlice(int $offset, ?int $length): iterable | ||
{ | ||
return array_slice($this->array, $offset, $length); | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SonsOfPHP\Component\Pager\Adapter; | ||
|
||
use SonsOfPHP\Contract\Pager\AdapterInterface; | ||
|
||
/** | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
class CallableAdapter implements AdapterInterface | ||
{ | ||
private $count; | ||
private $slice; | ||
|
||
public function __construct(callable $count, callable $slice) | ||
{ | ||
$this->count = $count; | ||
$this->slice = $slice; | ||
} | ||
|
||
public function count(): int | ||
{ | ||
return call_user_func($this->count); | ||
} | ||
|
||
public function getSlice(int $offset, ?int $length): iterable | ||
{ | ||
return call_user_func($this->slice, $offset, $length); | ||
} | ||
} |
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,19 @@ | ||
Copyright 2022 to Present Joshua Estes | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Oops, something went wrong.