Pagination.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Rest\Pagination;
  6. use Temando\Shipping\Webservice\Pagination\PaginationInterface;
  7. /**
  8. * Webservice Pagination
  9. *
  10. * JSON API style, example: /completions?page[limit]=200&page[offset]=400
  11. *
  12. * @package Temando\Shipping\Webservice
  13. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  14. * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  15. * @link https://www.temando.com/
  16. */
  17. class Pagination implements PaginationInterface
  18. {
  19. /**
  20. * @var int
  21. */
  22. private $offset;
  23. /**
  24. * @var int
  25. */
  26. private $limit;
  27. /**
  28. * Pagination constructor.
  29. * @param int $offset
  30. * @param int $limit
  31. */
  32. public function __construct($offset = null, $limit = null)
  33. {
  34. $this->offset = $offset;
  35. $this->limit = $limit;
  36. }
  37. /**
  38. * @return string[]
  39. */
  40. public function getPageParams()
  41. {
  42. if ($this->limit === null) {
  43. return [];
  44. }
  45. $params = [
  46. 'page' => [
  47. 'offset' => (int)$this->offset,
  48. 'limit' => (int)$this->limit,
  49. ],
  50. ];
  51. return $params;
  52. }
  53. }