Rfc3986Serializer.php 742 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace GuzzleHttp\Command\Guzzle\QuerySerializer;
  3. class Rfc3986Serializer implements QuerySerializerInterface
  4. {
  5. /**
  6. * @var bool
  7. */
  8. private $removeNumericIndices;
  9. /**
  10. * @param bool $removeNumericIndices
  11. */
  12. public function __construct($removeNumericIndices = false)
  13. {
  14. $this->removeNumericIndices = $removeNumericIndices;
  15. }
  16. /**
  17. * {@inheritDoc}
  18. */
  19. public function aggregate(array $queryParams)
  20. {
  21. $queryString = http_build_query($queryParams, null, '&', PHP_QUERY_RFC3986);
  22. if ($this->removeNumericIndices) {
  23. $queryString = preg_replace('/%5B[0-9]+%5D/simU', '%5B%5D', $queryString);
  24. }
  25. return $queryString;
  26. }
  27. }