Skip to content

Commit

Permalink
Improved performance of QueryDefaultsPlugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
vudaltsov committed Jan 4, 2018
1 parent 9accb4a commit 9e17bab
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/Plugin/QueryDefaultsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,14 @@ public function __construct(array $queryParams)
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first)
{
foreach ($this->queryParams as $name => $value) {
$uri = $request->getUri();
$array = [];
parse_str($uri->getQuery(), $array);

// If query value is not found
if (!isset($array[$name])) {
$array[$name] = $value;

// Create a new request with the new URI with the added query param
$request = $request->withUri(
$uri->withQuery(http_build_query($array))
);
}
}
$uri = $request->getUri();

parse_str($uri->getQuery(), $query);
$query += $this->queryParams;

$request = $request->withUri(
$uri->withQuery(http_build_query($query))
);

return $next($request);
}
Expand Down

0 comments on commit 9e17bab

Please sign in to comment.