Skip to content

Commit 451fb13

Browse files
Merge branch '2.8' into 3.1
* 2.8: [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 73074d9 + 90ec171 commit 451fb13

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
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: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* DelegatingLoader delegates route loading to other loaders using a loader resolver.
2121
*
2222
* This implementation resolves the _controller attribute from the short notation
23-
* to the fully-qualified form (from a:b:c to class:method).
23+
* to the fully-qualified form (from a:b:c to class::method).
2424
*
2525
* @author Fabien Potencier <[email protected]>
2626
*/
@@ -75,15 +75,17 @@ public function load($resource, $type = null)
7575
}
7676

7777
foreach ($collection->all() as $route) {
78-
if ($controller = $route->getDefault('_controller')) {
79-
try {
80-
$controller = $this->parser->parse($controller);
81-
} catch (\InvalidArgumentException $e) {
82-
// unable to optimize unknown notation
83-
}
78+
if (!$controller = $route->getDefault('_controller')) {
79+
continue;
80+
}
8481

85-
$route->setDefault('_controller', $controller);
82+
try {
83+
$controller = $this->parser->parse($controller);
84+
} catch (\InvalidArgumentException $e) {
85+
// unable to optimize unknown notation
8686
}
87+
88+
$route->setDefault('_controller', $controller);
8789
}
8890

8991
return $collection;

0 commit comments

Comments
 (0)