From f66683690046d40454d19470f5d1dadcc434d5e5 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Wed, 11 Apr 2012 18:27:19 +0200 Subject: [PATCH] [Routing] simplified regex with named variables --- .../Matcher/Dumper/ApacheMatcherDumper.php | 2 +- .../Matcher/Dumper/PhpMatcherDumper.php | 2 +- .../Component/Routing/RouteCompiler.php | 4 +-- .../Tests/Fixtures/dumper/url_matcher1.php | 36 +++++++++---------- .../Tests/Fixtures/dumper/url_matcher2.php | 36 +++++++++---------- .../Tests/Fixtures/dumper/url_matcher3.php | 2 +- .../Routing/Tests/RouteCompilerTest.php | 14 ++++---- 7 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php index d0d7739c1b..743cebdcdf 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php @@ -56,7 +56,7 @@ class ApacheMatcherDumper extends MatcherDumper if (strlen($regex) < 2 || 0 === $regexPatternEnd) { throw new \LogicException('The "%s" route regex "%s" is invalid', $name, $regex); } - $regex = preg_replace('/\?P<.+?>/', '', substr($regex, 1, $regexPatternEnd - 1)); + $regex = preg_replace('/\?<.+?>/', '', substr($regex, 1, $regexPatternEnd - 1)); $regex = '^'.self::escape(preg_quote($options['base_uri']).substr($regex, 1), ' ', '\\'); $methods = array(); diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index 5fb3e3fd82..bc26c0cd0f 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -191,7 +191,7 @@ EOF; $supportsTrailingSlash = $supportsRedirections && (!$methods || in_array('HEAD', $methods)); - if (!count($compiledRoute->getVariables()) && false !== preg_match('#^(.)\^(?P.*?)\$\1#', $compiledRoute->getRegex(), $m)) { + if (!count($compiledRoute->getVariables()) && false !== preg_match('#^(.)\^(?.*?)\$\1#', $compiledRoute->getRegex(), $m)) { if ($supportsTrailingSlash && substr($m['url'], -1) === '/') { $conditions[] = sprintf("rtrim(\$pathinfo, '/') === %s", var_export(rtrim(str_replace('\\', '', $m['url']), '/'), true)); $hasTrailingSlash = true; diff --git a/src/Symfony/Component/Routing/RouteCompiler.php b/src/Symfony/Component/Routing/RouteCompiler.php index e816de4954..29ac4e48e9 100644 --- a/src/Symfony/Component/Routing/RouteCompiler.php +++ b/src/Symfony/Component/Routing/RouteCompiler.php @@ -108,10 +108,10 @@ class RouteCompiler implements RouteCompilerInterface // Variable tokens if (0 === $index && 0 === $firstOptional && 1 == count($tokens)) { // When the only token is an optional variable token, the separator is required - return sprintf('%s(?P<%s>%s)?', preg_quote($token[1], '#'), $token[3], $token[2]); + return sprintf('%s(?<%s>%s)?', preg_quote($token[1], '#'), $token[3], $token[2]); } else { $nbTokens = count($tokens); - $regexp = sprintf('%s(?P<%s>%s)', preg_quote($token[1], '#'), $token[3], $token[2]); + $regexp = sprintf('%s(?<%s>%s)', preg_quote($token[1], '#'), $token[3], $token[2]); if ($index >= $firstOptional) { // Enclose each optional tokens in a subpattern to make it optional $regexp = "(?:$regexp"; diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php index 4753410ffa..2c764d0df3 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php @@ -26,12 +26,12 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher $pathinfo = rawurldecode($pathinfo); // foo - if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?Pbaz|symfony)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?baz|symfony)$#s', $pathinfo, $matches)) { return array_merge($this->mergeDefaults($matches, array ( 'def' => 'test',)), array('_route' => 'foo')); } // bar - if (0 === strpos($pathinfo, '/bar') && preg_match('#^/bar/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/bar') && preg_match('#^/bar/(?[^/]+?)$#s', $pathinfo, $matches)) { if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) { $allow = array_merge($allow, array('GET', 'HEAD')); goto not_bar; @@ -42,7 +42,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher not_bar: // barhead - if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?[^/]+?)$#s', $pathinfo, $matches)) { if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) { $allow = array_merge($allow, array('GET', 'HEAD')); goto not_barhead; @@ -68,13 +68,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher } // baz4 - if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/]+?)/$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+?)/$#s', $pathinfo, $matches)) { $matches['_route'] = 'baz4'; return $matches; } // baz5 - if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/]+?)/$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+?)/$#s', $pathinfo, $matches)) { if ($this->context->getMethod() != 'POST') { $allow[] = 'POST'; goto not_baz5; @@ -85,7 +85,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher not_baz5: // baz.baz6 - if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/]+?)/$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+?)/$#s', $pathinfo, $matches)) { if ($this->context->getMethod() != 'PUT') { $allow[] = 'PUT'; goto not_bazbaz6; @@ -101,7 +101,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher } // quoter - if (preg_match('#^/(?P[\']+)$#s', $pathinfo, $matches)) { + if (preg_match('#^/(?[\']+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'quoter'; return $matches; } @@ -114,13 +114,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (0 === strpos($pathinfo, '/a')) { if (0 === strpos($pathinfo, '/a/b\'b')) { // foo1 - if (preg_match('#^/a/b\'b/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'foo1'; return $matches; } // bar1 - if (preg_match('#^/a/b\'b/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'bar1'; return $matches; } @@ -128,20 +128,20 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher } // overriden - if (preg_match('#^/a/(?P.*)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/(?.*)$#s', $pathinfo, $matches)) { $matches['_route'] = 'overriden'; return $matches; } if (0 === strpos($pathinfo, '/a/b\'b')) { // foo2 - if (preg_match('#^/a/b\'b/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'foo2'; return $matches; } // bar2 - if (preg_match('#^/a/b\'b/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'bar2'; return $matches; } @@ -152,7 +152,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (0 === strpos($pathinfo, '/multi')) { // helloWorld - if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?P[^/]+?))?$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?[^/]+?))?$#s', $pathinfo, $matches)) { return array_merge($this->mergeDefaults($matches, array ( 'who' => 'World!',)), array('_route' => 'helloWorld')); } @@ -169,13 +169,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher } // foo3 - if (preg_match('#^/(?P<_locale>[^/]+?)/b/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/(?<_locale>[^/]+?)/b/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'foo3'; return $matches; } // bar3 - if (preg_match('#^/(?P<_locale>[^/]+?)/b/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/(?<_locale>[^/]+?)/b/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'bar3'; return $matches; } @@ -186,7 +186,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher } // foo4 - if (0 === strpos($pathinfo, '/aba') && preg_match('#^/aba/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/aba') && preg_match('#^/aba/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'foo4'; return $matches; } @@ -199,13 +199,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (0 === strpos($pathinfo, '/a/b')) { // b - if (preg_match('#^/a/b/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'b'; return $matches; } // c - if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'c'; return $matches; } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php index dbfd28ab0a..4b9af5c5a1 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php @@ -26,12 +26,12 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec $pathinfo = rawurldecode($pathinfo); // foo - if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?Pbaz|symfony)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?baz|symfony)$#s', $pathinfo, $matches)) { return array_merge($this->mergeDefaults($matches, array ( 'def' => 'test',)), array('_route' => 'foo')); } // bar - if (0 === strpos($pathinfo, '/bar') && preg_match('#^/bar/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/bar') && preg_match('#^/bar/(?[^/]+?)$#s', $pathinfo, $matches)) { if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) { $allow = array_merge($allow, array('GET', 'HEAD')); goto not_bar; @@ -42,7 +42,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec not_bar: // barhead - if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?[^/]+?)$#s', $pathinfo, $matches)) { if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) { $allow = array_merge($allow, array('GET', 'HEAD')); goto not_barhead; @@ -71,7 +71,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec } // baz4 - if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/]+?)/?$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+?)/?$#s', $pathinfo, $matches)) { if (substr($pathinfo, -1) !== '/') { return $this->redirect($pathinfo.'/', 'baz4'); } @@ -80,7 +80,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec } // baz5 - if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/]+?)/$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+?)/$#s', $pathinfo, $matches)) { if ($this->context->getMethod() != 'POST') { $allow[] = 'POST'; goto not_baz5; @@ -91,7 +91,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec not_baz5: // baz.baz6 - if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/]+?)/$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?[^/]+?)/$#s', $pathinfo, $matches)) { if ($this->context->getMethod() != 'PUT') { $allow[] = 'PUT'; goto not_bazbaz6; @@ -107,7 +107,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec } // quoter - if (preg_match('#^/(?P[\']+)$#s', $pathinfo, $matches)) { + if (preg_match('#^/(?[\']+)$#s', $pathinfo, $matches)) { $matches['_route'] = 'quoter'; return $matches; } @@ -120,13 +120,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if (0 === strpos($pathinfo, '/a')) { if (0 === strpos($pathinfo, '/a/b\'b')) { // foo1 - if (preg_match('#^/a/b\'b/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'foo1'; return $matches; } // bar1 - if (preg_match('#^/a/b\'b/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'bar1'; return $matches; } @@ -134,20 +134,20 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec } // overriden - if (preg_match('#^/a/(?P.*)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/(?.*)$#s', $pathinfo, $matches)) { $matches['_route'] = 'overriden'; return $matches; } if (0 === strpos($pathinfo, '/a/b\'b')) { // foo2 - if (preg_match('#^/a/b\'b/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'foo2'; return $matches; } // bar2 - if (preg_match('#^/a/b\'b/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b\'b/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'bar2'; return $matches; } @@ -158,7 +158,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if (0 === strpos($pathinfo, '/multi')) { // helloWorld - if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?P[^/]+?))?$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?[^/]+?))?$#s', $pathinfo, $matches)) { return array_merge($this->mergeDefaults($matches, array ( 'who' => 'World!',)), array('_route' => 'helloWorld')); } @@ -178,13 +178,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec } // foo3 - if (preg_match('#^/(?P<_locale>[^/]+?)/b/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/(?<_locale>[^/]+?)/b/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'foo3'; return $matches; } // bar3 - if (preg_match('#^/(?P<_locale>[^/]+?)/b/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/(?<_locale>[^/]+?)/b/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'bar3'; return $matches; } @@ -195,7 +195,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec } // foo4 - if (0 === strpos($pathinfo, '/aba') && preg_match('#^/aba/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/aba') && preg_match('#^/aba/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'foo4'; return $matches; } @@ -208,13 +208,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if (0 === strpos($pathinfo, '/a/b')) { // b - if (preg_match('#^/a/b/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/a/b/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'b'; return $matches; } // c - if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'c'; return $matches; } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php index 2dc0be9886..3373931ba6 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php @@ -32,7 +32,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher } // dynamic - if (preg_match('#^/rootprefix/(?P[^/]+?)$#s', $pathinfo, $matches)) { + if (preg_match('#^/rootprefix/(?[^/]+?)$#s', $pathinfo, $matches)) { $matches['_route'] = 'dynamic'; return $matches; } diff --git a/src/Symfony/Component/Routing/Tests/RouteCompilerTest.php b/src/Symfony/Component/Routing/Tests/RouteCompilerTest.php index afe6f6c4a0..7245e7909c 100644 --- a/src/Symfony/Component/Routing/Tests/RouteCompilerTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteCompilerTest.php @@ -43,7 +43,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase array( 'Route with a variable', array('/foo/{bar}'), - '/foo', '#^/foo/(?P[^/]+?)$#s', array('bar'), array( + '/foo', '#^/foo/(?[^/]+?)$#s', array('bar'), array( array('variable', '/', '[^/]+?', 'bar'), array('text', '/foo'), )), @@ -51,7 +51,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase array( 'Route with a variable that has a default value', array('/foo/{bar}', array('bar' => 'bar')), - '/foo', '#^/foo(?:/(?P[^/]+?))?$#s', array('bar'), array( + '/foo', '#^/foo(?:/(?[^/]+?))?$#s', array('bar'), array( array('variable', '/', '[^/]+?', 'bar'), array('text', '/foo'), )), @@ -59,7 +59,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase array( 'Route with several variables', array('/foo/{bar}/{foobar}'), - '/foo', '#^/foo/(?P[^/]+?)/(?P[^/]+?)$#s', array('bar', 'foobar'), array( + '/foo', '#^/foo/(?[^/]+?)/(?[^/]+?)$#s', array('bar', 'foobar'), array( array('variable', '/', '[^/]+?', 'foobar'), array('variable', '/', '[^/]+?', 'bar'), array('text', '/foo'), @@ -68,7 +68,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase array( 'Route with several variables that have default values', array('/foo/{bar}/{foobar}', array('bar' => 'bar', 'foobar' => '')), - '/foo', '#^/foo(?:/(?P[^/]+?)(?:/(?P[^/]+?))?)?$#s', array('bar', 'foobar'), array( + '/foo', '#^/foo(?:/(?[^/]+?)(?:/(?[^/]+?))?)?$#s', array('bar', 'foobar'), array( array('variable', '/', '[^/]+?', 'foobar'), array('variable', '/', '[^/]+?', 'bar'), array('text', '/foo'), @@ -77,7 +77,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase array( 'Route with several variables but some of them have no default values', array('/foo/{bar}/{foobar}', array('bar' => 'bar')), - '/foo', '#^/foo/(?P[^/]+?)/(?P[^/]+?)$#s', array('bar', 'foobar'), array( + '/foo', '#^/foo/(?[^/]+?)/(?[^/]+?)$#s', array('bar', 'foobar'), array( array('variable', '/', '[^/]+?', 'foobar'), array('variable', '/', '[^/]+?', 'bar'), array('text', '/foo'), @@ -86,14 +86,14 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase array( 'Route with an optional variable as the first segment', array('/{bar}', array('bar' => 'bar')), - '', '#^/(?P[^/]+?)?$#s', array('bar'), array( + '', '#^/(?[^/]+?)?$#s', array('bar'), array( array('variable', '/', '[^/]+?', 'bar'), )), array( 'Route with an optional variable as the first segment with requirements', array('/{bar}', array('bar' => 'bar'), array('bar' => '(foo|bar)')), - '', '#^/(?P(foo|bar))?$#s', array('bar'), array( + '', '#^/(?(foo|bar))?$#s', array('bar'), array( array('variable', '/', '(foo|bar)', 'bar'), )), );