-
-
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 - [ ] Unit Tests Created - [x] php-cs-fixer
- Loading branch information
1 parent
f3b1dd0
commit 40b9991
Showing
13 changed files
with
234 additions
and
14 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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 |
---|---|---|
|
@@ -102,6 +102,10 @@ | |
"path": "src/SonsOfPHP/Contract/Money", | ||
"repository": "[email protected]:SonsOfPHP/money-contract.git" | ||
}, | ||
{ | ||
"path": "src/SonsOfPHP/Contract/Pager", | ||
"repository": "[email protected]:SonsOfPHP/pager-contract.git" | ||
}, | ||
{ | ||
"path": "src/SonsOfPHP/Contract/Version", | ||
"repository": "[email protected]:SonsOfPHP/version-contract.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
title: Pager Contract | ||
--- | ||
|
||
The PHP Pager Contract is to support libraries that implement Pagination related | ||
components. | ||
|
||
## Installation | ||
|
||
```shell | ||
composer require sonsofphp/pager-contract | ||
``` |
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,2 @@ | ||
/.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,2 @@ | ||
composer.lock | ||
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SonsOfPHP\Contract\Pager; | ||
|
||
/** | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
interface AdapterInterface extends \Countable | ||
{ | ||
/** | ||
* This will return part of the total results | ||
* | ||
* Offset is where the results to be returned will start, for example, if | ||
* offset is 0, it will start with the first record and return $length | ||
* | ||
* Offset should always be 0 or greater | ||
* | ||
* Length is how many results to return. For example, if length is 10, a | ||
* MAXIMUM of 10 results will be returned | ||
* | ||
* Length should always be a positive number that is 1 or greater | ||
* | ||
* If null is passed in as length, this should return ALL the results. | ||
* | ||
* If the total number of results is less than length, an exception must | ||
* not be thrown. | ||
* | ||
* @throws \InvalidArgumentException | ||
* If offset or length is invalid, this expection will be thrown | ||
*/ | ||
public function getSlice(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
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. |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SonsOfPHP\Contract\Pager; | ||
|
||
/** | ||
* Generic Pager Exception | ||
* | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
interface PagerExceptionInterface {} |
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,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SonsOfPHP\Contract\Pager; | ||
|
||
/** | ||
* The pager should take an adapter and optional arguments when being created. | ||
* | ||
* Example: | ||
* new Pager($adapter, ['current_page' => 2, 'max_per_page' => 10]); | ||
* | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
interface PagerInterface extends \Countable, \IteratorAggregate, \JsonSerializable | ||
{ | ||
/** | ||
* This will return the current results based on the current page and max | ||
* results per page | ||
*/ | ||
public function getCurrentPageResults(): iterable; | ||
|
||
public function getTotalResults(): int; | ||
|
||
public function getTotalPages(): int; | ||
|
||
public function haveToPaginate(): bool; | ||
|
||
public function hasPreviousPage(): bool; | ||
|
||
/** | ||
* If there is no previous page, this will return null | ||
*/ | ||
public function getPreviousPage(): ?int; | ||
|
||
public function hasNextPage(): bool; | ||
|
||
/** | ||
* If there is no next page, this will return null | ||
*/ | ||
public function getNextPage(): ?int; | ||
|
||
/** | ||
* Returns the current page | ||
* | ||
* This should default to 1 if no current page is set. | ||
*/ | ||
public function getCurrentPage(): int; | ||
|
||
/** | ||
* The page must be 1 or greater | ||
* | ||
* If the page is out of bounds, this may throw an exception | ||
* | ||
* @throws \InvalidArgumentException | ||
* If $page is invalid | ||
*/ | ||
public function setCurrentPage(int $page): void; | ||
|
||
/** | ||
* This should return a default value if not set | ||
* | ||
* If max per page is set to null, this will return null | ||
*/ | ||
public function getMaxPerPage(): ?int; | ||
|
||
/** | ||
* The max per page should be a value of 1 or greater. | ||
* | ||
* If the value is set to null, and results are grabbed, all the results | ||
* will be returned. | ||
* | ||
* @throws \InvalidArgumentException | ||
* If $maxPerPage is invalid | ||
*/ | ||
public function setMaxPerPage(?int $maxPerPage): void; | ||
} |
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,16 @@ | ||
Sons of PHP - Pager Contract | ||
============================ | ||
|
||
## Learn More | ||
|
||
* [Documentation][docs] | ||
* [Contributing][contributing] | ||
* [Report Issues][issues] and [Submit Pull Requests][pull-requests] in the [Mother Repository][mother-repo] | ||
* Get Help & Support using [Discussions][discussions] | ||
|
||
[discussions]: https://github.com/orgs/SonsOfPHP/discussions | ||
[mother-repo]: https://github.com/SonsOfPHP/sonsofphp | ||
[contributing]: https://docs.sonsofphp.com/contributing/ | ||
[docs]: https://docs.sonsofphp.com/contracts/pager/ | ||
[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3APager | ||
[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3APager |
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,52 @@ | ||
{ | ||
"name": "sonsofphp/pager-contract", | ||
"type": "library", | ||
"description": "", | ||
"keywords": [ | ||
"abstractions", | ||
"contracts", | ||
"decoupling", | ||
"interfaces", | ||
"interoperability", | ||
"standards" | ||
], | ||
"homepage": "https://github.com/SonsOfPHP/pager-contract", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Joshua Estes", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/SonsOfPHP/sonsofphp/issues", | ||
"forum": "https://github.com/orgs/SonsOfPHP/discussions", | ||
"docs": "https://docs.sonsofphp.com" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"SonsOfPHP\\Contract\\Pager\\": "" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"require": { | ||
"php": ">=8.1" | ||
}, | ||
"extra": { | ||
"sort-packages": true, | ||
"branch-alias": { | ||
"dev-main": "0.3.x-dev" | ||
} | ||
}, | ||
"funding": [ | ||
{ | ||
"type": "github", | ||
"url": "https://github.com/sponsors/JoshuaEstes" | ||
}, | ||
{ | ||
"type": "tidelift", | ||
"url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp" | ||
} | ||
] | ||
} |