You are here

private function Uri::filterQuery in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-diactoros/src/Uri.php \Zend\Diactoros\Uri::filterQuery()

Filter a query string to ensure it is propertly encoded.

Ensures that the values in the query string are properly urlencoded.

Parameters

string $query:

Return value

string

2 calls to Uri::filterQuery()
Uri::parseUri in vendor/zendframework/zend-diactoros/src/Uri.php
Parse a URI into its parts, and set the properties
Uri::withQuery in vendor/zendframework/zend-diactoros/src/Uri.php
Return an instance with the specified query string.

File

vendor/zendframework/zend-diactoros/src/Uri.php, line 581

Class

Uri
Implementation of Psr\Http\UriInterface.

Namespace

Zend\Diactoros

Code

private function filterQuery($query) {
  if (!empty($query) && strpos($query, '?') === 0) {
    $query = substr($query, 1);
  }
  $parts = explode('&', $query);
  foreach ($parts as $index => $part) {
    list($key, $value) = $this
      ->splitQueryValue($part);
    if ($value === null) {
      $parts[$index] = $this
        ->filterQueryOrFragment($key);
      continue;
    }
    $parts[$index] = sprintf('%s=%s', $this
      ->filterQueryOrFragment($key), $this
      ->filterQueryOrFragment($value));
  }
  return implode('&', $parts);
}