Skip to content

Commit

Permalink
Fixed Route::withQueryParam() to accept array values
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed May 14, 2018
1 parent 2c82e15 commit 5ab956a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Added `Grav\Common\Page` interface to allow custom page types in the future
1. [](#bugfix)
* Fixed bug in `ContentBlock` serialization
* Fixed `Route::withQueryParam()` to accept array values

# v1.4.4
## 04/12/2018
Expand Down
9 changes: 4 additions & 5 deletions system/src/Grav/Framework/Route/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function getQueryParam($param)
*/
public function withGravParam($param, $value)
{
return $this->withParam('gravParams', $param, $value);
return $this->withParam('gravParams', $param, null !== $value ? (string)$value : null);
}

/**
Expand Down Expand Up @@ -222,17 +222,16 @@ public function __toString()
protected function withParam($type, $param, $value)
{
$oldValue = isset($this->{$type}[$param]) ? $this->{$type}[$param] : null;
$newValue = null !== $value ? (string)$value : null;

if ($oldValue === $newValue) {
if ($oldValue === $value) {
return $this;
}

$new = clone $this;
if ($newValue === null) {
if ($value === null) {
unset($new->{$type}[$param]);
} else {
$new->{$type}[$param] = $newValue;
$new->{$type}[$param] = $value;
}

return $new;
Expand Down

0 comments on commit 5ab956a

Please sign in to comment.