10000 [Routing] made RouteCompilerInterface::compile static · symfony/symfony@5d264ce · GitHub
[go: up one dir, main page]

Skip to content

Commit 5d264ce

Browse files
Tobionfabpot
authored andcommitted
[Routing] made RouteCompilerInterface::compile static
1 parent 1f281db commit 5d264ce

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

src/Symfony/Component/Routing/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ CHANGELOG
7979
pass the requirements (otherwise it would break your link anyway).
8080
* There is no restriction on the route name anymore. So non-alphanumeric characters
8181
are now also allowed.
82+
* [BC BREAK] `RouteCompilerInterface::compile(Route $route)` was made static
83+
(only relevant if you implemented your own RouteCompiler).
8284

8385
2.1.0
8486
-----

src/Symfony/Component/Routing/Route.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ class Route implements \Serializable
5050
*/
5151
private $compiled;
5252

53-
private static $compilers = array();
54-
5553
/**
5654
* Constructor.
5755
*
@@ -421,6 +419,9 @@ public function setRequirement($key, $regex)
421419
*
422420
* @return CompiledRoute A CompiledRoute instance
423421
*
422+
* @throws \LogicException If the Route cannot be compiled because the
423+
* path or hostname pattern is invalid
424+
*
424425
* @see RouteCompiler which is responsible for the compilation process
425426
*/
426427
public function compile()
@@ -431,11 +432,7 @@ public function compile()
431432

432433
$class = $this->getOption('compiler_class');
433434

434-
if (!isset(self::$compilers[$class])) {
435-
self::$compilers[$class] = new $class;
436-
}
437-
438-
return $this->compiled = self::$compilers[$class]->compile($this);
435+
return $this->compiled = $class::compile($this);
439436
}
440437

441438
private function sanitizeRequirement($key, $regex)

src/Symfony/Component/Routing/RouteCompiler.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class RouteCompiler implements RouteCompilerInterface
3535
* @throws \DomainException If a variable name is numeric because PHP raises an error for such
3636
* subpatterns in PCRE and thus would break matching, e.g. "(?P<123>.+)".
3737
*/
38-
public function compile(Route $route)
38+
public static function compile(Route $route)
3939
{
4040
$staticPrefix = null;
4141
$hostnameVariables = array();
@@ -47,7 +47,7 @@ public function compile(Route $route)
4747
$hostnameTokens = array();
4848

4949
if ('' !== $hostnamePattern = $route->getHostnamePattern()) {
50-
$result = $this->compilePattern($route, $hostnamePattern, true);
50+
$result = self::compilePattern($route, $hostnamePattern, true);
5151

5252
$hostnameVariables = $result['variables'];
5353
$variables = array_merge($variables, $hostnameVariables);
@@ -58,7 +58,7 @@ public function compile(Route $route)
5858

5959
$pattern = $route->getPattern();
6060

61-
$result = $this->compilePattern($route, $pattern, false);
61+
$result = self::compilePattern($route, $pattern, false);
6262

6363
$staticPrefix = $result['staticPrefix'];
6464

@@ -80,7 +80,7 @@ public function compile(Route $route)
8080
);
8181
}
8282

83-
private function compilePattern(Route $route, $pattern, $isHostname)
83+
private static function compilePattern(Route $route, $pattern, $isHostname)
8484
{
8585
$tokens = array();
8686
$variables = array();
@@ -122,7 +122,7 @@ private function compilePattern(Route $route, $pattern, $isHostname)
122122
// If {page} would also match the separating dot, {_format} would never match as {page} will eagerly consume everything.
123123
// Also even if {_format} was not optional the requirement prevents that {page} matches something that was originally
124124
// part of {_format} when generating the URL, e.g. _format = 'mobile.html'.
125-
$nextSeparator = $this->findNextSeparator($followingPattern);
125+
$nextSeparator = self::findNextSeparator($followingPattern);
126126
$regexp = sprintf(
127127
'[^%s%s]+',
128128
preg_quote($defaultSeparator, self::REGEX_DELIMITER),
@@ -162,7 +162,7 @@ private function compilePattern(Route $route, $pattern, $isHostname)
162162
// compute the matching regexp
163163
$regexp = '';
164164
for ($i = 0, $nbToken = count($tokens); $i < $nbToken; $i++) {
165-
$regexp .= $this->computeRegexp($tokens, $i, $firstOptional);
165+
$regexp .= self::computeRegexp($tokens, $i, $firstOptional);
166166
}
167167

168168
return array(
@@ -180,7 +180,7 @@ private function compilePattern(Route $route, $pattern, $isHostname)
180180
*
181181
* @return string The next static character that functions as separator (or empty string when none available)
182182
*/
183-
private function findNextSeparator($pattern)
183+
private static function findNextSeparator($pattern)
184184
{
185185
if ('' == $pattern) {
186186
// return empty string if pattern is empty or false (false which can be returned by substr)
@@ -201,7 +201,7 @@ private function findNextSeparator($pattern)
201201
*
202202
* @return string The regexp pattern for a single token
203203
*/
204-
private function computeRegexp(array $tokens, $index, $firstOptional)
204+
private static function computeRegexp(array $tokens, $index, $firstOptional)
205205
{
206206
$token = $tokens[$index];
207207
if ('text' === $token[0]) {

src/Symfony/Component/Routing/RouteCompilerInterface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ interface RouteCompilerInterface
2424
* @param Route $route A Route instance
2525
*
2626
* @return CompiledRoute A CompiledRoute instance
27+
*
28+
* @throws \LogicException If the Route cannot be compiled because the
29+
* path or hostname pattern is invalid
2730
*/
28-
public function compile(Route $route);
31+
public static function compile(Route $route);
2932
}

0 commit comments

Comments
 (0)
0