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 e571f99

Browse filesBrowse files
committed
[FrameworkBundle] Improve performance of ControllerNameParser
1 parent 620ea20 commit e571f99
Copy full SHA for e571f99

File tree

2 files changed

+15
-10
lines changed
Filter options

2 files changed

+15
-10
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php
+3-2Lines 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();

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php
+12-8Lines changed: 12 additions & 8 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,15 +85,19 @@ public function load($resource, $type = null)
8585
$this->loading = false;
8686

8787
foreach ($collection->all() as $route) {
88-
if ($controller = $route->getDefault('_controller')) {
89-
try {
90-
$controller = $this->parser->parse($controller);
91-
} catch (\InvalidArgumentException $e) {
92-
// unable to optimize unknown notation
93-
}
88+
$controller = $route->getDefault('_controller');
89+
// If $controller is in class::method notation already skip it for performance.
90+
if (! $controller || false !== strpos($controller, '::')) {
91+
continue;
92+
}
9493

95-
$route->setDefault('_controller', $controller);
94+
try {
95+
$controller = $this->parser->parse($controller);
96+
} catch (\InvalidArgumentException $e) {
97+
// unable to optimize unknown notation
9698
}
99+
100+
$route->setDefault('_controller', $controller);
97101
}
98102

99103
return $collection;

0 commit comments

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