Skip to content

Commit 90ec171

Browse files
Merge branch '2.7' into 2.8
* 2.7: [Routing] Fail properly when a route parameter name cannot be used as a PCRE subpattern name [FrameworkBundle] Improve performance of ControllerNameParser Update documentation link to the component [HttpFoundation] Add links to RFC-7231 [DI] Initialize properties before method calls Tag missing internals [WebProfilerBundle] Dont use request attributes in RouterController Fix complete config tests
2 parents dae0501 + a4b116b commit 90ec171

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

Controller/ControllerNameParser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ public function __construct(KernelInterface $kernel)
4646
*/
4747
public function parse($controller)
4848
{
49-
$originalController = $controller;
50-
if (3 !== count($parts = explode(':', $controller))) {
49+
$parts = explode(':', $controller);
50+
if (3 !== count($parts) || in_array('', $parts, true)) {
5151
throw new \InvalidArgumentException(sprintf('The "%s" controller is not a valid "a:b:c" controller string.', $controller));
5252
}
5353

54+
$originalController = $controller;
5455
list($bundle, $controller, $action) = $parts;
5556
$controller = str_replace('/', '\\', $controller);
5657
$bundles = array();

Routing/DelegatingLoader.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* DelegatingLoader delegates route loading to other loaders using a loader resolver.
2222
*
2323
* This implementation resolves the _controller attribute from the short notation
24-
* to the fully-qualified form (from a:b:c to class:method).
24+
* to the fully-qualified form (from a:b:c to class::method).
2525
*
2626
* @author Fabien Potencier <[email protected]>
2727
*/
@@ -92,15 +92,17 @@ public function load($resource, $type = null)
9292
$this->loading = false;
9393

9494
foreach ($collection->all() as $route) {
95-
if ($controller = $route->getDefault('_controller')) {
96-
try {
97-
$controller = $this->parser->parse($controller);
98-
} catch (\InvalidArgumentException $e) {
99-
// unable to optimize unknown notation
100-
}
101-
102-
$route->setDefault('_controller', $controller);
95+
if (!$controller = $route->getDefault('_controller')) {
96+
continue;
10397
}
98+
99+
try {
100+
$controller = $this->parser->parse($controller);
101+
} catch (\InvalidArgumentException $e) {
102+
// unable to optimize unknown notation
103+
}
104+
105+
$route->setDefault('_controller', $controller);
104106
}
105107

106108
return $collection;

0 commit comments

Comments
 (0)