ListRequest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Rest\Request;
  6. use Temando\Shipping\Webservice\Filter\CollectionFilterInterface;
  7. use Temando\Shipping\Webservice\Pagination\PaginationInterface;
  8. /**
  9. * Temando API Item Listing Operation
  10. *
  11. * @package Temando\Shipping\Rest
  12. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  13. * @author Sebastian Ertner <sebastian.ertner@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 ListRequest implements ListRequestInterface
  18. {
  19. /**
  20. * The list's parent entity, e.g. /book/{parentId}/chapters.
  21. *
  22. * @var string
  23. */
  24. private $parentId;
  25. /**
  26. * Pagination parameters.
  27. *
  28. * @var PaginationInterface
  29. */
  30. private $pagination;
  31. /**
  32. * Limit and offset parameters.
  33. *
  34. * @var CollectionFilterInterface
  35. */
  36. private $filter;
  37. /**
  38. * ListRequest constructor.
  39. * @param string $parentId
  40. * @param PaginationInterface $pagination
  41. * @param CollectionFilterInterface $filter
  42. */
  43. public function __construct(
  44. $parentId = '',
  45. PaginationInterface $pagination = null,
  46. CollectionFilterInterface $filter = null
  47. ) {
  48. $this->parentId = $parentId;
  49. $this->pagination = $pagination;
  50. $this->filter = $filter;
  51. }
  52. /**
  53. * @return string[]
  54. */
  55. public function getPathParams()
  56. {
  57. return $this->parentId ? [$this->parentId] : [];
  58. }
  59. /**
  60. * Retrieve query parameters for listings.
  61. *
  62. * @return string[]
  63. */
  64. public function getRequestParams()
  65. {
  66. if ($this->pagination instanceof PaginationInterface) {
  67. $pageParams = $this->pagination->getPageParams();
  68. } else {
  69. $pageParams = [];
  70. }
  71. if ($this->filter instanceof CollectionFilterInterface) {
  72. $filterParams = $this->filter->getFilters();
  73. } else {
  74. $filterParams = [];
  75. }
  76. $requestParams = array_merge($pageParams, $filterParams);
  77. return $requestParams;
  78. }
  79. }