aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2013-11-20 12:56:49 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2013-11-20 12:56:49 +0100
commitde7732ff5f2ed4bd65eb935688ed370abfff1735 (patch)
tree486ece9cef3e0da447a92ed8490413ffb4bf6090
parent9496f4ad92fa0741caf707c70168ec1af44ffe94 (diff)
downloadRouter-de7732ff5f2ed4bd65eb935688ed370abfff1735.zip
Router-de7732ff5f2ed4bd65eb935688ed370abfff1735.tar.gz
Router-de7732ff5f2ed4bd65eb935688ed370abfff1735.tar.bz2
unroute() supports more complex patterns.
-rw-r--r--Http.php14
1 files changed, 14 insertions, 0 deletions
diff --git a/Http.php b/Http.php
index f081d6e..49c4960 100644
--- a/Http.php
+++ b/Http.php
@@ -590,6 +590,7 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
protected function _unroute ( $id, $pattern, Array $variables,
$allowEmpty = true ) {
+ // (?<named>…)
$out = preg_replace_callback(
'#\(\?\<([^>]+)>[^\)]*\)[\?\*\+]{0,2}#',
function ( Array $matches ) use ( &$id, &$variables, &$allowEmpty ) {
@@ -607,9 +608,22 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
return $variables[$m];
},
+ // (-…)
preg_replace('#\(\?\-?[imsxUXJ]+\)#', '', $pattern)
);
+ // (?:
+ $out = preg_replace('#(?<!\\\)\(\?:#', '(', $out);
+
+ // (…)?, (…)*
+ $out = preg_replace('#(?<!\\\)\((.*)(?<!\\\)\)[\?\*]#', '\1', $out);
+
+ // (…)+
+ $out = preg_replace('#(?<!\\\)\((.+)(?<!\\\)\)\+#', '\1', $out);
+
+ // …?, …*, …+
+ $out = preg_replace('#(.)(?<![\)\\\])[\?\*\+]#', '\1', $out);
+
return str_replace(
array(
'\.', '\\\\', '\+', '\*', '\?', '\[', '\]', '\^', '\$', '\(',