Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8867f57

Browse filesBrowse files
committed
feature #35857 [Routing] deprecate RouteCompiler::REGEX_DELIMITER (nicolas-grekas)
This PR was merged into the 5.1-dev branch. Discussion ---------- [Routing] deprecate RouteCompiler::REGEX_DELIMITER | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | - | License | MIT | Doc PR | - This should be mostly internal cleanup. Commits ------- 21b8a64 [Routing] deprecate RouteCompiler::REGEX_DELIMITER
2 parents 28a249f + 21b8a64 commit 8867f57
Copy full SHA for 8867f57

12 files changed

+57
-53
lines changed

‎UPGRADE-5.1.md

Copy file name to clipboardExpand all lines: UPGRADE-5.1.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Routing
5959

6060
* Deprecated `RouteCollectionBuilder` in favor of `RoutingConfigurator`.
6161
* Added argument `$priority` to `RouteCollection::add()`
62+
* Deprecated the `RouteCompiler::REGEX_DELIMITER` constant
6263

6364
Yaml
6465
----

‎UPGRADE-6.0.md

Copy file name to clipboardExpand all lines: UPGRADE-6.0.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ Routing
4848

4949
* Removed `RouteCollectionBuilder`.
5050
* Added argument `$priority` to `RouteCollection::add()`
51+
* Removed the `RouteCompiler::REGEX_DELIMITER` constant

‎src/Symfony/Component/Routing/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* deprecated `RouteCollectionBuilder` in favor of `RoutingConfigurator`.
99
* added "priority" option to annotated routes
1010
* added argument `$priority` to `RouteCollection::add()`
11+
* deprecated the `RouteCompiler::REGEX_DELIMITER` constant
1112

1213
5.0.0
1314
-----

‎src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\Routing\Annotation\Route as RouteAnnotation;
1919
use Symfony\Component\Routing\Route;
2020
use Symfony\Component\Routing\RouteCollection;
21-
use Symfony\Component\Routing\RouteCompiler;
2221

2322
/**
2423
* AnnotationClassLoader loads routing information from a PHP class and its methods.
@@ -206,7 +205,7 @@ protected function addRoute(RouteCollection $collection, $annot, array $globals,
206205
$this->configureRoute($route, $class, $method, $annot);
207206
if (0 !== $locale) {
208207
$route->setDefault('_locale', $locale);
209-
$route->setRequirement('_locale', preg_quote($locale, RouteCompiler::REGEX_DELIMITER));
208+
$route->setRequirement('_locale', preg_quote($locale));
210209
$route->setDefault('_canonical_route', $name);
211210
$collection->add($name.'.'.$locale, $route, $priority);
212211
} else {

‎src/Symfony/Component/Routing/Loader/Configurator/Traits/LocalizedRouteTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/Configurator/Traits/LocalizedRouteTrait.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Component\Routing\Route;
1515
use Symfony\Component\Routing\RouteCollection;
16-
use Symfony\Component\Routing\RouteCompiler;
1716

1817
/**
1918
* @internal
@@ -64,7 +63,7 @@ final protected function createLocalizedRoute(RouteCollection $collection, strin
6463
$routes->add($name.'.'.$locale, $route = $this->createRoute($path));
6564
$collection->add($namePrefix.$name.'.'.$locale, $route);
6665
$route->setDefault('_locale', $locale);
67-
$route->setRequirement('_locale', preg_quote($locale, RouteCompiler::REGEX_DELIMITER));
66+
$route->setRequirement('_locale', preg_quote($locale));
6867
$route->setDefault('_canonical_route', $namePrefix.$name);
6968
}
7069

‎src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherTrait.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ private function doMatch(string $pathinfo, array &$allow = [], array &$allowSche
9393
}
9494

9595
if ($requiredHost) {
96-
if ('#' !== $requiredHost[0] ? $requiredHost !== $host : !preg_match($requiredHost, $host, $hostMatches)) {
96+
if ('{' !== $requiredHost[0] ? $requiredHost !== $host : !preg_match($requiredHost, $host, $hostMatches)) {
9797
continue;
9898
}
99-
if ('#' === $requiredHost[0] && $hostMatches) {
99+
if ('{' === $requiredHost[0] && $hostMatches) {
100100
$hostMatches['_route'] = $ret['_route'];
101101
$ret = $this->mergeDefaults($hostMatches, $ret);
102102
}

‎src/Symfony/Component/Routing/RouteCompiler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/RouteCompiler.php
+9-6Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
*/
2020
class RouteCompiler implements RouteCompilerInterface
2121
{
22+
/**
23+
* @deprecated since Symfony 5.1, to be removed in 6.0
24+
*/
2225
const REGEX_DELIMITER = '#';
2326

2427
/**
@@ -161,8 +164,8 @@ private static function compilePattern(Route $route, string $pattern, bool $isHo
161164
$nextSeparator = self::findNextSeparator($followingPattern, $useUtf8);
162165
$regexp = sprintf(
163166
'[^%s%s]+',
164-
preg_quote($defaultSeparator, self::REGEX_DELIMITER),
165-
$defaultSeparator !== $nextSeparator && '' !== $nextSeparator ? preg_quote($nextSeparator, self::REGEX_DELIMITER) : ''
167+
preg_quote($defaultSeparator),
168+
$defaultSeparator !== $nextSeparator && '' !== $nextSeparator ? preg_quote($nextSeparator) : ''
166169
);
167170
if (('' !== $nextSeparator && !preg_match('#^\{\w+\}#', $followingPattern)) || '' === $followingPattern) {
168171
// When we have a separator, which is disallowed for the variable, we can optimize the regex with a possessive
@@ -217,7 +220,7 @@ private static function compilePattern(Route $route, string $pattern, bool $isHo
217220
for ($i = 0, $nbToken = \count($tokens); $i < $nbToken; ++$i) {
218221
$regexp .= self::computeRegexp($tokens, $i, $firstOptional);
219222
}
220-
$regexp = self::REGEX_DELIMITER.'^'.$regexp.'$'.self::REGEX_DELIMITER.'sD'.($isHost ? 'i' : '');
223+
$regexp = '{^'.$regexp.'$}sD'.($isHost ? 'i' : '');
221224

222225
// enable Utf8 matching if really required
223226
if ($needsUtf8) {
@@ -289,14 +292,14 @@ private static function computeRegexp(array $tokens, int $index, int $firstOptio
289292
$token = $tokens[$index];
290293
if ('text' === $token[0]) {
291294
// Text tokens
292-
return preg_quote($token[1], self::REGEX_DELIMITER);
295+
return preg_quote($token[1]);
293296
} else {
294297
// Variable tokens
295298
if (0 === $index && 0 === $firstOptional) {
296299
// When the only token is an optional variable token, the separator is required
297-
return sprintf('%s(?P<%s>%s)?', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
300+
return sprintf('%s(?P<%s>%s)?', preg_quote($token[1]), $token[3], $token[2]);
298301
} else {
299-
$regexp = sprintf('%s(?P<%s>%s)', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
302+
$regexp = sprintf('%s(?P<%s>%s)', preg_quote($token[1]), $token[3], $token[2]);
300303
if ($index >= $firstOptional) {
301304
// Enclose each optional token in a subpattern to make it optional.
302305
// "?:" means it is non-capturing, i.e. the portion of the subject string that

‎src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher1.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher1.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
'/c2/route3' => [[['_route' => 'route3'], 'b.example.com', null, null, false, false, null]],
2323
'/route5' => [[['_route' => 'route5'], 'c.example.com', null, null, false, false, null]],
2424
'/route6' => [[['_route' => 'route6'], null, null, null, false, false, null]],
25-
'/route11' => [[['_route' => 'route11'], '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false, false, null]],
26-
'/route12' => [[['_route' => 'route12', 'var1' => 'val'], '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false, false, null]],
25+
'/route11' => [[['_route' => 'route11'], '{^(?P<var1>[^\\.]++)\\.example\\.com$}sDi', null, null, false, false, null]],
26+
'/route12' => [[['_route' => 'route12', 'var1' => 'val'], '{^(?P<var1>[^\\.]++)\\.example\\.com$}sDi', null, null, false, false, null]],
2727
'/route17' => [[['_route' => 'route17'], null, null, null, false, false, null]],
2828
],
2929
[ // $regexpList

‎src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher2.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher2.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
'/c2/route3' => [[['_route' => 'route3'], 'b.example.com', null, null, false, false, null]],
2323
'/route5' => [[['_route' => 'route5'], 'c.example.com', null, null, false, false, null]],
2424
'/route6' => [[['_route' => 'route6'], null, null, null, false, false, null]],
25-
'/route11' => [[['_route' => 'route11'], '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false, false, null]],
26-
'/route12' => [[['_route' => 'route12', 'var1' => 'val'], '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false, false, null]],
25+
'/route11' => [[['_route' => 'route11'], '{^(?P<var1>[^\\.]++)\\.example\\.com$}sDi', null, null, false, false, null]],
26+
'/route12' => [[['_route' => 'route12', 'var1' => 'val'], '{^(?P<var1>[^\\.]++)\\.example\\.com$}sDi', null, null, false, false, null]],
2727
'/route17' => [[['_route' => 'route17'], null, null, null, false, false, null]],
2828
'/secure' => [[['_route' => 'secure'], null, null, ['https' => 0], false, false, null]],
2929
'/nonsecure' => [[['_route' => 'nonsecure'], null, null, ['http' => 0], false, false, null]],

‎src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher9.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Fixtures/dumper/compiled_url_matcher9.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
true, // $matchHost
1010
[ // $staticRoutes
1111
'/' => [
12-
[['_route' => 'a'], '#^(?P<d>[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', null, null, false, false, null],
13-
[['_route' => 'c'], '#^(?P<e>[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', null, null, false, false, null],
12+
[['_route' => 'a'], '{^(?P<d>[^\\.]++)\\.e\\.c\\.b\\.a$}sDi', null, null, false, false, null],
13+
[['_route' => 'c'], '{^(?P<e>[^\\.]++)\\.e\\.c\\.b\\.a$}sDi', null, null, false, false, null],
1414
[['_route' => 'b'], 'd.c.b.a', null, null, false, false, null],
1515
],
1616
],

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.