aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKévin Gomez <contact@kevingomez.fr>2015-07-16 23:02:02 +0200
committerKévin Gomez <contact@kevingomez.fr>2015-07-16 23:02:02 +0200
commit9a9e938c78cc603e24a6ae907592a34555fabaf1 (patch)
tree154e1210503b00e017925928e9d422b9346e1d13
parentf56bee7c912344650fce56995b4bdee3ffd7e621 (diff)
downloadRouter-9a9e938c78cc603e24a6ae907592a34555fabaf1.zip
Router-9a9e938c78cc603e24a6ae907592a34555fabaf1.tar.gz
Router-9a9e938c78cc603e24a6ae907592a34555fabaf1.tar.bz2
Append unused variables to the querystring when unrouting rules
-rw-r--r--Http/Http.php10
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) : '');
}
/**