-
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.
- Loading branch information
Showing
4 changed files
with
98 additions
and
1 deletion.
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\PeakWMS\DataTransferObject; | ||
|
||
/** | ||
* @template T of AbstractDataTransferObject | ||
* | ||
* @extends Collection<T> | ||
*/ | ||
final class PaginatedCollection extends Collection | ||
{ | ||
/** | ||
* @param list<T> $items | ||
*/ | ||
public function __construct( | ||
array $items = [], | ||
public readonly int $page = 0, | ||
public readonly int $pageSize = 0, | ||
public readonly int $totalRecords = 0, | ||
) { | ||
parent::__construct($items); | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\PeakWMS\Request\Query\Product; | ||
|
||
use Setono\PeakWMS\Request\Query\Query; | ||
|
||
final class PageQuery extends Query | ||
{ | ||
/** | ||
* @param int $page The first page is 0, not 1 | ||
* @param int $pageSize The maximum page size is 100 | ||
*/ | ||
public static function create(int $page = 0, int $pageSize = 100, \DateTimeInterface $updatedAfter = null): self | ||
{ | ||
return new self(array_filter([ | ||
'Page' => $page, | ||
'PageSize' => $pageSize, | ||
'updatedAfter' => $updatedAfter, | ||
], static fn ($value): bool => null !== $value)); | ||
} | ||
|
||
/** | ||
* @throws \LogicException If the page parameter is not set or is not an integer | ||
*/ | ||
public function incrementPage(): void | ||
{ | ||
if (!isset($this->parameters['Page']) || !is_int($this->parameters['Page'])) { | ||
throw new \LogicException('The page parameter must be set and be an integer'); | ||
} | ||
|
||
++$this->parameters['Page']; | ||
} | ||
} |