diff --git a/UPGRADE-5.1.md b/UPGRADE-5.1.md index 656f0b5d5d..e61de91734 100644 --- a/UPGRADE-5.1.md +++ b/UPGRADE-5.1.md @@ -59,6 +59,7 @@ Routing * Deprecated `RouteCollectionBuilder` in favor of `RoutingConfigurator`. * Added argument `$priority` to `RouteCollection::add()` + * Deprecated the `RouteCompiler::REGEX_DELIMITER` constant Yaml ---- diff --git a/UPGRADE-6.0.md b/UPGRADE-6.0.md index 1dfdf1bfda..8df8c5e144 100644 --- a/UPGRADE-6.0.md +++ b/UPGRADE-6.0.md @@ -48,3 +48,4 @@ Routing * Removed `RouteCollectionBuilder`. * Added argument `$priority` to `RouteCollection::add()` + * Removed the `RouteCompiler::REGEX_DELIMITER` constant diff --git a/src/Symfony/Component/Routing/CHANGELOG.md b/src/Symfony/Component/Routing/CHANGELOG.md index 4c04edcb2f..8c712e0e0b 100644 --- a/src/Symfony/Component/Routing/CHANGELOG.md +++ b/src/Symfony/Component/Routing/CHANGELOG.md @@ -8,6 +8,7 @@ CHANGELOG * deprecated `RouteCollectionBuilder` in favor of `RoutingConfigurator`. * added "priority" option to annotated routes * added argument `$priority` to `RouteCollection::add()` + * deprecated the `RouteCompiler::REGEX_DELIMITER` constant 5.0.0 ----- diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index b286a70495..8800e89854 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -18,7 +18,6 @@ use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Routing\Annotation\Route as RouteAnnotation; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; -use Symfony\Component\Routing\RouteCompiler; /** * AnnotationClassLoader loads routing information from a PHP class and its methods. @@ -206,7 +205,7 @@ abstract class AnnotationClassLoader implements LoaderInterface $this->configureRoute($route, $class, $method, $annot); if (0 !== $locale) { $route->setDefault('_locale', $locale); - $route->setRequirement('_locale', preg_quote($locale, RouteCompiler::REGEX_DELIMITER)); + $route->setRequirement('_locale', preg_quote($locale)); $route->setDefault('_canonical_route', $name); $collection->add($name.'.'.$locale, $route, $priority); } else { diff --git a/src/Symfony/Component/Routing/Loader/Configurator/Traits/LocalizedRouteTrait.php b/src/Symfony/Component/Routing/Loader/Configurator/Traits/LocalizedRouteTrait.php index a24c256f25..8bd54095f6 100644 --- a/src/Symfony/Component/Routing/Loader/Configurator/Traits/LocalizedRouteTrait.php +++ b/src/Symfony/Component/Routing/Loader/Configurator/Traits/LocalizedRouteTrait.php @@ -13,7 +13,6 @@ namespace Symfony\Component\Routing\Loader\Configurator\Traits; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; -use Symfony\Component\Routing\RouteCompiler; /** * @internal @@ -64,7 +63,7 @@ trait LocalizedRouteTrait $routes->add($name.'.'.$locale, $route = $this->createRoute($path)); $collection->add($namePrefix.$name.'.'.$locale, $route); $route->setDefault('_locale', $locale); - $route->setRequirement('_locale', preg_quote($locale, RouteCompiler::REGEX_DELIMITER)); + $route->setRequirement('_locale', preg_quote($locale)); $route->setDefault('_canonical_route', $namePrefix.$name); } diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherTrait.php b/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherTrait.php index c5980b1548..caba4e5c62 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherTrait.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherTrait.php @@ -93,10 +93,10 @@ trait CompiledUrlMatcherTrait } if ($requiredHost) { - if ('#' !== $requiredHost[0] ? $requiredHost !== $host : !preg_match($requiredHost, $host, $hostMatches)) { + if ('{' !== $requiredHost[0] ? $requiredHost !== $host : !preg_match($requiredHost, $host, $hostMatches)) { continue; } - if ('#' === $requiredHost[0] && $hostMatches) { + if ('{' === $requiredHost[0] && $hostMatches) { $hostMatches['_route'] = $ret['_route']; $ret = $this->mergeDefaults($hostMatches, $ret); } diff --git a/src/Symfony/Component/Routing/RouteCompiler.php b/src/Symfony/Component/Routing/RouteCompiler.php index 59f3a327e0..2fc92e6879 100644 --- a/src/Symfony/Component/Routing/RouteCompiler.php +++ b/src/Symfony/Component/Routing/RouteCompiler.php @@ -19,6 +19,9 @@ namespace Symfony\Component\Routing; */ class RouteCompiler implements RouteCompilerInterface { + /** + * @deprecated since Symfony 5.1, to be removed in 6.0 + */ const REGEX_DELIMITER = '#'; /** @@ -161,8 +164,8 @@ class RouteCompiler implements RouteCompilerInterface $nextSeparator = self::findNextSeparator($followingPattern, $useUtf8); $regexp = sprintf( '[^%s%s]+', - preg_quote($defaultSeparator, self::REGEX_DELIMITER), - $defaultSeparator !== $nextSeparator && '' !== $nextSeparator ? preg_quote($nextSeparator, self::REGEX_DELIMITER) : '' + preg_quote($defaultSeparator), + $defaultSeparator !== $nextSeparator && '' !== $nextSeparator ? preg_quote($nextSeparator) : '' ); if (('' !== $nextSeparator && !preg_match('#^\{\w+\}#', $followingPattern)) || '' === $followingPattern) { // When we have a separator, which is disallowed for the variable, we can optimize the regex with a possessive @@ -217,7 +220,7 @@ class RouteCompiler implements RouteCompilerInterface for ($i = 0, $nbToken = \count($tokens); $i < $nbToken; ++$i) { $regexp .= self::computeRegexp($tokens, $i, $firstOptional); } - $regexp = self::REGEX_DELIMITER.'^'.$regexp.'$'.self::REGEX_DELIMITER.'sD'.($isHost ? 'i' : ''); + $regexp = '{^'.$regexp.'$}sD'.($isHost ? 'i' : ''); // enable Utf8 matching if really required if ($needsUtf8) { @@ -289,14 +292,14 @@ class RouteCompiler implements RouteCompilerInterface $token = $tokens[$index]; if ('text' === $token[0]) { // Text tokens - return preg_quote($token[1], self::REGEX_DELIMITER); + return preg_quote($token[1]); } else { // Variable tokens if (0 === $index && 0 === $firstOptional) { // When the only token is an optional variable token, the separator is required - return sprintf('%s(?P<%s>%s)?', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]); + return sprintf('%s(?P<%s>%s)?', preg_quote($token[1]), $token[3], $token[2]); } else { - $regexp = sprintf('%s(?P<%s>%s)', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]); + $regexp = sprintf('%s(?P<%s>%s)', preg_quote($token[1]), $token[3], $token[2]); if ($index >= $firstOptional) { // Enclose each optional token in a subpattern to make it optional. // "?:" means it is non-capturing, i.e. the portion of the subject string that diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher1.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher1.php index 7811f150a8..b96a267023 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher1.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher1.php @@ -22,8 +22,8 @@ return [ '/c2/route3' => [[['_route' => 'route3'], 'b.example.com', null, null, false, false, null]], '/route5' => [[['_route' => 'route5'], 'c.example.com', null, null, false, false, null]], '/route6' => [[['_route' => 'route6'], null, null, null, false, false, null]], - '/route11' => [[['_route' => 'route11'], '#^(?P[^\\.]++)\\.example\\.com$#sDi', null, null, false, false, null]], - '/route12' => [[['_route' => 'route12', 'var1' => 'val'], '#^(?P[^\\.]++)\\.example\\.com$#sDi', null, null, false, false, null]], + '/route11' => [[['_route' => 'route11'], '{^(?P[^\\.]++)\\.example\\.com$}sDi', null, null, false, false, null]], + '/route12' => [[['_route' => 'route12', 'var1' => 'val'], '{^(?P[^\\.]++)\\.example\\.com$}sDi', null, null, false, false, null]], '/route17' => [[['_route' => 'route17'], null, null, null, false, false, null]], ], [ // $regexpList diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher2.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher2.php index 13629954a8..f675aca43b 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher2.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher2.php @@ -22,8 +22,8 @@ return [ '/c2/route3' => [[['_route' => 'route3'], 'b.example.com', null, null, false, false, null]], '/route5' => [[['_route' => 'route5'], 'c.example.com', null, null, false, false, null]], '/route6' => [[['_route' => 'route6'], null, null, null, false, false, null]], - '/route11' => [[['_route' => 'route11'], '#^(?P[^\\.]++)\\.example\\.com$#sDi', null, null, false, false, null]], - '/route12' => [[['_route' => 'route12', 'var1' => 'val'], '#^(?P[^\\.]++)\\.example\\.com$#sDi', null, null, false, false, null]], + '/route11' => [[['_route' => 'route11'], '{^(?P[^\\.]++)\\.example\\.com$}sDi', null, null, false, false, null]], + '/route12' => [[['_route' => 'route12', 'var1' => 'val'], '{^(?P[^\\.]++)\\.example\\.com$}sDi', null, null, false, false, null]], '/route17' => [[['_route' => 'route17'], null, null, null, false, false, null]], '/secure' => [[['_route' => 'secure'], null, null, ['https' => 0], false, false, null]], '/nonsecure' => [[['_route' => 'nonsecure'], null, null, ['http' => 0], false, false, null]], diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher9.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher9.php index da1c8a706f..5103529d61 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher9.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher9.php @@ -9,8 +9,8 @@ return [ true, // $matchHost [ // $staticRoutes '/' => [ - [['_route' => 'a'], '#^(?P[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', null, null, false, false, null], - [['_route' => 'c'], '#^(?P[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', null, null, false, false, null], + [['_route' => 'a'], '{^(?P[^\\.]++)\\.e\\.c\\.b\\.a$}sDi', null, null, false, false, null], + [['_route' => 'c'], '{^(?P[^\\.]++)\\.e\\.c\\.b\\.a$}sDi', null, null, false, false, null], [['_route' => 'b'], 'd.c.b.a', null, null, false, false, null], ], ], diff --git a/src/Symfony/Component/Routing/Tests/RouteCompilerTest.php b/src/Symfony/Component/Routing/Tests/RouteCompilerTest.php index 5729d4caa5..85d3908aab 100644 --- a/src/Symfony/Component/Routing/Tests/RouteCompilerTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteCompilerTest.php @@ -38,7 +38,7 @@ class RouteCompilerTest extends TestCase [ 'Static route', ['/foo'], - '/foo', '#^/foo$#sD', [], [ + '/foo', '{^/foo$}sD', [], [ ['text', '/foo'], ], ], @@ -46,7 +46,7 @@ class RouteCompilerTest extends TestCase [ 'Route with a variable', ['/foo/{bar}'], - '/foo', '#^/foo/(?P[^/]++)$#sD', ['bar'], [ + '/foo', '{^/foo/(?P[^/]++)$}sD', ['bar'], [ ['variable', '/', '[^/]++', 'bar'], ['text', '/foo'], ], @@ -55,7 +55,7 @@ class RouteCompilerTest extends TestCase [ 'Route with a variable that has a default value', ['/foo/{bar}', ['bar' => 'bar']], - '/foo', '#^/foo(?:/(?P[^/]++))?$#sD', ['bar'], [ + '/foo', '{^/foo(?:/(?P[^/]++))?$}sD', ['bar'], [ ['variable', '/', '[^/]++', 'bar'], ['text', '/foo'], ], @@ -64,7 +64,7 @@ class RouteCompilerTest extends TestCase [ 'Route with several variables', ['/foo/{bar}/{foobar}'], - '/foo', '#^/foo/(?P[^/]++)/(?P[^/]++)$#sD', ['bar', 'foobar'], [ + '/foo', '{^/foo/(?P[^/]++)/(?P[^/]++)$}sD', ['bar', 'foobar'], [ ['variable', '/', '[^/]++', 'foobar'], ['variable', '/', '[^/]++', 'bar'], ['text', '/foo'], @@ -74,7 +74,7 @@ class RouteCompilerTest extends TestCase [ 'Route with several variables that have default values', ['/foo/{bar}/{foobar}', ['bar' => 'bar', 'foobar' => '']], - '/foo', '#^/foo(?:/(?P[^/]++)(?:/(?P[^/]++))?)?$#sD', ['bar', 'foobar'], [ + '/foo', '{^/foo(?:/(?P[^/]++)(?:/(?P[^/]++))?)?$}sD', ['bar', 'foobar'], [ ['variable', '/', '[^/]++', 'foobar'], ['variable', '/', '[^/]++', 'bar'], ['text', '/foo'], @@ -84,7 +84,7 @@ class RouteCompilerTest extends TestCase [ 'Route with several variables but some of them have no default values', ['/foo/{bar}/{foobar}', ['bar' => 'bar']], - '/foo', '#^/foo/(?P[^/]++)/(?P[^/]++)$#sD', ['bar', 'foobar'], [ + '/foo', '{^/foo/(?P[^/]++)/(?P[^/]++)$}sD', ['bar', 'foobar'], [ ['variable', '/', '[^/]++', 'foobar'], ['variable', '/', '[^/]++', 'bar'], ['text', '/foo'], @@ -94,7 +94,7 @@ class RouteCompilerTest extends TestCase [ 'Route with an optional variable as the first segment', ['/{bar}', ['bar' => 'bar']], - '', '#^/(?P[^/]++)?$#sD', ['bar'], [ + '', '{^/(?P[^/]++)?$}sD', ['bar'], [ ['variable', '/', '[^/]++', 'bar'], ], ], @@ -102,7 +102,7 @@ class RouteCompilerTest extends TestCase [ 'Route with a requirement of 0', ['/{bar}', ['bar' => null], ['bar' => '0']], - '', '#^/(?P0)?$#sD', ['bar'], [ + '', '{^/(?P0)?$}sD', ['bar'], [ ['variable', '/', '0', 'bar'], ], ], @@ -110,7 +110,7 @@ class RouteCompilerTest extends TestCase [ 'Route with an optional variable as the first segment with requirements', ['/{bar}', ['bar' => 'bar'], ['bar' => '(foo|bar)']], - '', '#^/(?P(?:foo|bar))?$#sD', ['bar'], [ + '', '{^/(?P(?:foo|bar))?$}sD', ['bar'], [ ['variable', '/', '(?:foo|bar)', 'bar'], ], ], @@ -118,7 +118,7 @@ class RouteCompilerTest extends TestCase [ 'Route with only optional variables', ['/{foo}/{bar}', ['foo' => 'foo', 'bar' => 'bar']], - '', '#^/(?P[^/]++)?(?:/(?P[^/]++))?$#sD', ['foo', 'bar'], [ + '', '{^/(?P[^/]++)?(?:/(?P[^/]++))?$}sD', ['foo', 'bar'], [ ['variable', '/', '[^/]++', 'bar'], ['variable', '/', '[^/]++', 'foo'], ], @@ -127,7 +127,7 @@ class RouteCompilerTest extends TestCase [ 'Route with a variable in last position', ['/foo-{bar}'], - '/foo-', '#^/foo\-(?P[^/]++)$#sD', ['bar'], [ + '/foo-', '{^/foo\-(?P[^/]++)$}sD', ['bar'], [ ['variable', '-', '[^/]++', 'bar'], ['text', '/foo'], ], @@ -136,7 +136,7 @@ class RouteCompilerTest extends TestCase [ 'Route with nested placeholders', ['/{static{var}static}'], - '/{static', '#^/\{static(?P[^/]+)static\}$#sD', ['var'], [ + '/{static', '{^/\{static(?P[^/]+)static\}$}sD', ['var'], [ ['text', 'static}'], ['variable', '', '[^/]+', 'var'], ['text', '/{static'], @@ -146,7 +146,7 @@ class RouteCompilerTest extends TestCase [ 'Route without separator between variables', ['/{w}{x}{y}{z}.{_format}', ['z' => 'default-z', '_format' => 'html'], ['y' => '(y|Y)']], - '', '#^/(?P[^/\.]+)(?P[^/\.]+)(?P(?:y|Y))(?:(?P[^/\.]++)(?:\.(?P<_format>[^/]++))?)?$#sD', ['w', 'x', 'y', 'z', '_format'], [ + '', '{^/(?P[^/\.]+)(?P[^/\.]+)(?P(?:y|Y))(?:(?P[^/\.]++)(?:\.(?P<_format>[^/]++))?)?$}sD', ['w', 'x', 'y', 'z', '_format'], [ ['variable', '.', '[^/]++', '_format'], ['variable', '', '[^/\.]++', 'z'], ['variable', '', '(?:y|Y)', 'y'], @@ -158,7 +158,7 @@ class RouteCompilerTest extends TestCase [ 'Route with a format', ['/foo/{bar}.{_format}'], - '/foo', '#^/foo/(?P[^/\.]++)\.(?P<_format>[^/]++)$#sD', ['bar', '_format'], [ + '/foo', '{^/foo/(?P[^/\.]++)\.(?P<_format>[^/]++)$}sD', ['bar', '_format'], [ ['variable', '.', '[^/]++', '_format'], ['variable', '/', '[^/\.]++', 'bar'], ['text', '/foo'], @@ -168,7 +168,7 @@ class RouteCompilerTest extends TestCase [ 'Static non UTF-8 route', ["/fo\xE9"], - "/fo\xE9", "#^/fo\xE9$#sD", [], [ + "/fo\xE9", "{^/fo\xE9$}sD", [], [ ['text', "/fo\xE9"], ], ], @@ -176,7 +176,7 @@ class RouteCompilerTest extends TestCase [ 'Route with an explicit UTF-8 requirement', ['/{bar}', ['bar' => null], ['bar' => '.'], ['utf8' => true]], - '', '#^/(?P.)?$#sDu', ['bar'], [ + '', '{^/(?P.)?$}sDu', ['bar'], [ ['variable', '/', '.', 'bar', true], ], ], @@ -205,7 +205,7 @@ class RouteCompilerTest extends TestCase [ 'Static UTF-8 route', ['/foé'], - '/foé', '#^/foé$#sDu', [], [ + '/foé', '{^/foé$}sDu', [], [ ['text', '/foé'], ], 'patterns', @@ -214,7 +214,7 @@ class RouteCompilerTest extends TestCase [ 'Route with an implicit UTF-8 requirement', ['/{bar}', ['bar' => null], ['bar' => 'é']], - '', '#^/(?Pé)?$#sDu', ['bar'], [ + '', '{^/(?Pé)?$}sDu', ['bar'], [ ['variable', '/', 'é', 'bar', true], ], 'requirements', @@ -223,7 +223,7 @@ class RouteCompilerTest extends TestCase [ 'Route with a UTF-8 class requirement', ['/{bar}', ['bar' => null], ['bar' => '\pM']], - '', '#^/(?P\pM)?$#sDu', ['bar'], [ + '', '{^/(?P\pM)?$}sDu', ['bar'], [ ['variable', '/', '\pM', 'bar', true], ], 'requirements', @@ -232,7 +232,7 @@ class RouteCompilerTest extends TestCase [ 'Route with a UTF-8 separator', ['/foo/{bar}§{_format}', [], [], ['compiler_class' => Utf8RouteCompiler::class]], - '/foo', '#^/foo/(?P[^/§]++)§(?P<_format>[^/]++)$#sDu', ['bar', '_format'], [ + '/foo', '{^/foo/(?P[^/§]++)§(?P<_format>[^/]++)$}sDu', ['bar', '_format'], [ ['variable', '§', '[^/]++', '_format', true], ['variable', '/', '[^/§]++', 'bar', true], ['text', '/foo'], @@ -318,21 +318,21 @@ class RouteCompilerTest extends TestCase [ 'Route with host pattern', ['/hello', [], [], [], 'www.example.com'], - '/hello', '#^/hello$#sD', [], [], [ + '/hello', '{^/hello$}sD', [], [], [ ['text', '/hello'], ], - '#^www\.example\.com$#sDi', [], [ + '{^www\.example\.com$}sDi', [], [ ['text', 'www.example.com'], ], ], [ 'Route with host pattern and some variables', ['/hello/{name}', [], [], [], 'www.example.{tld}'], - '/hello', '#^/hello/(?P[^/]++)$#sD', ['tld', 'name'], ['name'], [ + '/hello', '{^/hello/(?P[^/]++)$}sD', ['tld', 'name'], ['name'], [ ['variable', '/', '[^/]++', 'name'], ['text', '/hello'], ], - '#^www\.example\.(?P[^\.]++)$#sDi', ['tld'], [ + '{^www\.example\.(?P[^\.]++)$}sDi', ['tld'], [ ['variable', '.', '[^\.]++', 'tld'], ['text', 'www.example'], ], @@ -340,10 +340,10 @@ class RouteCompilerTest extends TestCase [ 'Route with variable at beginning of host', ['/hello', [], [], [], '{locale}.example.{tld}'], - '/hello', '#^/hello$#sD', ['locale', 'tld'], [], [ + '/hello', '{^/hello$}sD', ['locale', 'tld'], [], [ ['text', '/hello'], ], - '#^(?P[^\.]++)\.example\.(?P[^\.]++)$#sDi', ['locale', 'tld'], [ + '{^(?P[^\.]++)\.example\.(?P[^\.]++)$}sDi', ['locale', 'tld'], [ ['variable', '.', '[^\.]++', 'tld'], ['text', '.example'], ['variable', '', '[^\.]++', 'locale'], @@ -352,10 +352,10 @@ class RouteCompilerTest extends TestCase [ 'Route with host variables that has a default value', ['/hello', ['locale' => 'a', 'tld' => 'b'], [], [], '{locale}.example.{tld}'], - '/hello', '#^/hello$#sD', ['locale', 'tld'], [], [ + '/hello', '{^/hello$}sD', ['locale', 'tld'], [], [ ['text', '/hello'], ], - '#^(?P[^\.]++)\.example\.(?P[^\.]++)$#sDi', ['locale', 'tld'], [ + '{^(?P[^\.]++)\.example\.(?P[^\.]++)$}sDi', ['locale', 'tld'], [ ['variable', '.', '[^\.]++', 'tld'], ['text', '.example'], ['variable', '', '[^\.]++', 'locale'], @@ -383,12 +383,12 @@ class RouteCompilerTest extends TestCase public function provideRemoveCapturingGroup() { - yield ['#^/(?Pa(?:b|c)(?:d|e)f)$#sD', 'a(b|c)(d|e)f']; - yield ['#^/(?Pa\(b\)c)$#sD', 'a\(b\)c']; - yield ['#^/(?P(?:b))$#sD', '(?:b)']; - yield ['#^/(?P(?(b)b))$#sD', '(?(b)b)']; - yield ['#^/(?P(*F))$#sD', '(*F)']; - yield ['#^/(?P(?:(?:foo)))$#sD', '((foo))']; + yield ['{^/(?Pa(?:b|c)(?:d|e)f)$}sD', 'a(b|c)(d|e)f']; + yield ['{^/(?Pa\(b\)c)$}sD', 'a\(b\)c']; + yield ['{^/(?P(?:b))$}sD', '(?:b)']; + yield ['{^/(?P(?(b)b))$}sD', '(?(b)b)']; + yield ['{^/(?P(*F))$}sD', '(*F)']; + yield ['{^/(?P(?:(?:foo)))$}sD', '((foo))']; } } diff --git a/src/Symfony/Component/Routing/Tests/RouteTest.php b/src/Symfony/Component/Routing/Tests/RouteTest.php index 93f397def2..36571ca027 100644 --- a/src/Symfony/Component/Routing/Tests/RouteTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteTest.php @@ -260,7 +260,7 @@ class RouteTest extends TestCase */ public function testSerializedRepresentationKeepsWorking() { - $serialized = 'C:31:"Symfony\Component\Routing\Route":936:{a:8:{s:4:"path";s:13:"/prefix/{foo}";s:4:"host";s:20:"{locale}.example.net";s:8:"defaults";a:1:{s:3:"foo";s:7:"default";}s:12:"requirements";a:1:{s:3:"foo";s:3:"\d+";}s:7:"options";a:1:{s:14:"compiler_class";s:39:"Symfony\Component\Routing\RouteCompiler";}s:7:"schemes";a:0:{}s:7:"methods";a:0:{}s:8:"compiled";C:39:"Symfony\Component\Routing\CompiledRoute":571:{a:8:{s:4:"vars";a:2:{i:0;s:6:"locale";i:1;s:3:"foo";}s:11:"path_prefix";s:7:"/prefix";s:10:"path_regex";s:31:"#^/prefix(?:/(?P\d+))?$#sD";s:11:"path_tokens";a:2:{i:0;a:4:{i:0;s:8:"variable";i:1;s:1:"/";i:2;s:3:"\d+";i:3;s:3:"foo";}i:1;a:2:{i:0;s:4:"text";i:1;s:7:"/prefix";}}s:9:"path_vars";a:1:{i:0;s:3:"foo";}s:10:"host_regex";s:40:"#^(?P[^\.]++)\.example\.net$#sDi";s:11:"host_tokens";a:2:{i:0;a:2:{i:0;s:4:"text";i:1;s:12:".example.net";}i:1;a:4:{i:0;s:8:"variable";i:1;s:0:"";i:2;s:7:"[^\.]++";i:3;s:6:"locale";}}s:9:"host_vars";a:1:{i:0;s:6:"locale";}}}}}'; + $serialized = 'C:31:"Symfony\Component\Routing\Route":936:{a:8:{s:4:"path";s:13:"/prefix/{foo}";s:4:"host";s:20:"{locale}.example.net";s:8:"defaults";a:1:{s:3:"foo";s:7:"default";}s:12:"requirements";a:1:{s:3:"foo";s:3:"\d+";}s:7:"options";a:1:{s:14:"compiler_class";s:39:"Symfony\Component\Routing\RouteCompiler";}s:7:"schemes";a:0:{}s:7:"methods";a:0:{}s:8:"compiled";C:39:"Symfony\Component\Routing\CompiledRoute":571:{a:8:{s:4:"vars";a:2:{i:0;s:6:"locale";i:1;s:3:"foo";}s:11:"path_prefix";s:7:"/prefix";s:10:"path_regex";s:31:"{^/prefix(?:/(?P\d+))?$}sD";s:11:"path_tokens";a:2:{i:0;a:4:{i:0;s:8:"variable";i:1;s:1:"/";i:2;s:3:"\d+";i:3;s:3:"foo";}i:1;a:2:{i:0;s:4:"text";i:1;s:7:"/prefix";}}s:9:"path_vars";a:1:{i:0;s:3:"foo";}s:10:"host_regex";s:40:"{^(?P[^\.]++)\.example\.net$}sDi";s:11:"host_tokens";a:2:{i:0;a:2:{i:0;s:4:"text";i:1;s:12:".example.net";}i:1;a:4:{i:0;s:8:"variable";i:1;s:0:"";i:2;s:7:"[^\.]++";i:3;s:6:"locale";}}s:9:"host_vars";a:1:{i:0;s:6:"locale";}}}}}'; $unserialized = unserialize($serialized); $route = new Route('/prefix/{foo}', ['foo' => 'default'], ['foo' => '\d+']);