diff options
author | Kévin Gomez <contact@kevingomez.fr> | 2015-07-16 23:02:02 +0200 |
---|---|---|
committer | Kévin Gomez <contact@kevingomez.fr> | 2015-07-16 23:02:02 +0200 |
commit | 9a9e938c78cc603e24a6ae907592a34555fabaf1 (patch) | |
tree | 154e1210503b00e017925928e9d422b9346e1d13 /Http | |
parent | f56bee7c912344650fce56995b4bdee3ffd7e621 (diff) | |
download | Router-9a9e938c78cc603e24a6ae907592a34555fabaf1.zip Router-9a9e938c78cc603e24a6ae907592a34555fabaf1.tar.gz Router-9a9e938c78cc603e24a6ae907592a34555fabaf1.tar.bz2 |
Append unused variables to the querystring when unrouting rules
Diffstat (limited to 'Http')
-rw-r--r-- | Http/Http.php | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Http/Http.php b/Http/Http.php index 6ee3fba..6996380 100644 --- a/Http/Http.php +++ b/Http/Http.php @@ -621,10 +621,12 @@ class Http extends Router\Generic implements Core\Parameter\Parameterizable Array $variables, $allowEmpty = true ) { + $unusedVariables = $variables; + // (?<named>…) $out = preg_replace_callback( '#\(\?\<([^>]+)>[^\)]*\)[\?\*\+]{0,2}#', - function (Array $matches) use (&$id, &$variables, &$allowEmpty) { + function (Array $matches) use (&$id, &$variables, &$allowEmpty, &$unusedVariables) { $m = strtolower($matches[1]); if (!isset($variables[$m]) || '' === $variables[$m]) { @@ -640,6 +642,8 @@ class Http extends Router\Generic implements Core\Parameter\Parameterizable } } + unset($unusedVariables[$m]); + return $variables[$m]; }, // (-…) @@ -658,7 +662,7 @@ class Http extends Router\Generic implements Core\Parameter\Parameterizable // …?, …*, …+ $out = preg_replace('#(.)(?<![\)\\\])[\?\*\+]#', '\1', $out); - return str_replace( + $out = str_replace( [ '\.', '\\\\', '\+', '\*', '\?', '\[', '\]', '\^', '\$', '\(', '\)', '\{', '\}', '\=', '\!', '\<', '\>', '\|', '\:', '\-' @@ -669,6 +673,8 @@ class Http extends Router\Generic implements Core\Parameter\Parameterizable ], $out ); + + return $out . (!empty($unusedVariables) ? '?' . http_build_query($unusedVariables) : ''); } /** |