Pagination.php 1.2 KB

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