[FrameworkBundle] Improve performance of ControllerNameParser
This commit is contained in:
parent
620ea20f49
commit
cf333f32c5
|
@ -46,11 +46,12 @@ class ControllerNameParser
|
|||
*/
|
||||
public function parse($controller)
|
||||
{
|
||||
$originalController = $controller;
|
||||
if (3 !== count($parts = explode(':', $controller))) {
|
||||
$parts = explode(':', $controller);
|
||||
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));
|
||||
}
|
||||
|
||||
$originalController = $controller;
|
||||
list($bundle, $controller, $action) = $parts;
|
||||
$controller = str_replace('/', '\\', $controller);
|
||||
$bundles = array();
|
||||
|
|
|
@ -21,7 +21,7 @@ use Psr\Log\LoggerInterface;
|
|||
* 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>
|
||||
*/
|
||||
|
@ -85,15 +85,18 @@ class DelegatingLoader extends BaseDelegatingLoader
|
|||
$this->loading = false;
|
||||
|
||||
foreach ($collection->all() as $route) {
|
||||
if ($controller = $route->getDefault('_controller')) {
|
||||
try {
|
||||
$controller = $this->parser->parse($controller);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
// unable to optimize unknown notation
|
||||
}
|
||||
|
||||
$route->setDefault('_controller', $controller);
|
||||
$controller = $route->getDefault('_controller');
|
||||
if (!$controller) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$controller = $this->parser->parse($controller);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
// unable to optimize unknown notation
|
||||
}
|
||||
|
||||
$route->setDefault('_controller', $controller);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
|
|
Reference in New Issue