Skip to content

Commit

Permalink
[FrameworkBundle] Improve performance of ControllerNameParser
Browse files Browse the repository at this point in the history
  • Loading branch information
enumag committed Nov 5, 2016
1 parent 620ea20 commit ac284c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Expand Up @@ -47,7 +47,12 @@ public function __construct(KernelInterface $kernel)
public function parse($controller)
{
$originalController = $controller;
if (3 !== count($parts = explode(':', $controller))) {
$parts = explode(':', $controller);

// The second condition is for cases when this method is called with the
// class::method string instead of a:b:c. It's important to fail early in this
// case because calling findAlternative needlessly is bad for performance.
if (3 !== count($parts) || in_array('', $parts, true)) {
throw new \InvalidArgumentException(sprintf('The "%s" controller is not a valid "a:b:c" controller string.', $controller));
}

Expand Down
Expand Up @@ -21,7 +21,7 @@
* DelegatingLoader delegates route loading to other loaders using a loader resolver.
*
* This implementation resolves the _controller attribute from the short notation
* to the fully-qualified form (from a:b:c to class:method).
* to the fully-qualified form (from a:b:c to class::method).
*
* @author Fabien Potencier <fabien@symfony.com>
*/
Expand Down Expand Up @@ -85,7 +85,8 @@ public function load($resource, $type = null)
$this->loading = false;

foreach ($collection->all() as $route) {
if ($controller = $route->getDefault('_controller')) {
$controller = $route->getDefault('_controller');
if ($controller && false === strpos($controller, '::')) {
try {
$controller = $this->parser->parse($controller);
} catch (\InvalidArgumentException $e) {
Expand Down

0 comments on commit ac284c3

Please sign in to comment.