Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf333f3

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

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/Symfony/Bundle/FrameworkBundle/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();

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

Lines changed: 11 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 <[email protected]>
2727
*/
@@ -85,15 +85,18 @@ 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) {
90+
continue;
91+
}
9492

95-
$route->setDefault('_controller', $controller);
93+
try {
94+
$controller = $this->parser->parse($controller);
95+
} catch (\InvalidArgumentException $e) {
96+
// unable to optimize unknown notation
9697
}
98+
99+
$route->setDefault('_controller', $controller);
97100
}
98101

99102
return $collection;

0 commit comments

Comments
 (0)