Skip to content

Commit 9e17bab

Browse files
committed
Improved performance of QueryDefaultsPlugin.
1 parent 9accb4a commit 9e17bab

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/Plugin/QueryDefaultsPlugin.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,14 @@ public function __construct(array $queryParams)
3333
*/
3434
public function handleRequest(RequestInterface $request, callable $next, callable $first)
3535
{
36-
foreach ($this->queryParams as $name => $value) {
37-
$uri = $request->getUri();
38-
$array = [];
39-
parse_str($uri->getQuery(), $array);
40-
41-
// If query value is not found
42-
if (!isset($array[$name])) {
43-
$array[$name] = $value;
44-
45-
// Create a new request with the new URI with the added query param
46-
$request = $request->withUri(
47-
$uri->withQuery(http_build_query($array))
48-
);
49-
}
50-
}
36+
$uri = $request->getUri();
37+
38+
parse_str($uri->getQuery(), $query);
39+
$query += $this->queryParams;
40+
41+
$request = $request->withUri(
42+
$uri->withQuery(http_build_query($query))
43+
);
5144

5245
return $next($request);
5346
}

0 commit comments

Comments
 (0)