8000 [FrameworkBundle] Improve performance of ControllerNameParser · symfony/symfony@ac284c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit ac284c3

Browse files
committed
[FrameworkBundle] Improve performance of ControllerNameParser
1 parent 620ea20 commit ac284c3

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ public function __construct(KernelInterface $kernel)
4747
public function parse($controller)
4848
{
4949
$originalController = $controller;
50-
if (3 !== count($parts = explode(':', $controller))) {
50+
$parts = explode(':', $controller);
51+
52+
// The second condition is for cases when this method is called with the
53+
// class::method string instead of a:b:c. It's important to fail early in this
54+
// case because calling findAlternative needlessly is bad for performance.
55+
if (3 !== count($parts) || in_array('', $parts, true)) {
5156
throw new \InvalidArgumentException(sprintf('The "%s" controller is not a valid "a:b:c" controller string.', $controller));
5257
}
5358

src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php

Lines changed: 3 additions & 2 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 <fabien@symfony.com>
2727
*/
@@ -85,7 +85,8 @@ public function load($resource, $type = null)
8585
$this->loading = false;
8686

8787
foreach ($collection->all() as $route) {
88-
if ($controller = $route->getDefault('_controller')) {
88+
$controller = $route->getDefault('_controller');
89+
if ($controller && false === strpos($controller, '::')) {
8990
try {
9091
$controller = $this->parser->parse($controller);
9192
} catch (\InvalidArgumentException $e) {

0 commit comments

Comments
 (0)
0