function ControllerResolver::getControllerFromDefinition
Same name and namespace in other branches
- 8.9.x core/lib/Drupal/Core/Controller/ControllerResolver.php \Drupal\Core\Controller\ControllerResolver::getControllerFromDefinition()
- 10 core/lib/Drupal/Core/Controller/ControllerResolver.php \Drupal\Core\Controller\ControllerResolver::getControllerFromDefinition()
- 11.x core/lib/Drupal/Core/Controller/ControllerResolver.php \Drupal\Core\Controller\ControllerResolver::getControllerFromDefinition()
Returns the Controller instance with a given controller route definition.
As several resolvers can exist for a single application, a resolver must return false when it is not able to determine the controller.
Parameters
mixed $controller: The controller attribute like in $request->attributes->get('_controller')
Return value
mixed|bool A PHP callable representing the Controller, or false if this resolver is not able to determine the controller
Overrides ControllerResolverInterface::getControllerFromDefinition
1 call to ControllerResolver::getControllerFromDefinition()
- ControllerResolver::getController in core/
lib/ Drupal/ Core/ Controller/ ControllerResolver.php
File
-
core/
lib/ Drupal/ Core/ Controller/ ControllerResolver.php, line 57
Class
- ControllerResolver
- ControllerResolver to enhance controllers beyond Symfony's basic handling.
Namespace
Drupal\Core\ControllerCode
public function getControllerFromDefinition($controller, $path = '') {
if (is_array($controller) || is_object($controller) && method_exists($controller, '__invoke')) {
return $controller;
}
if (strpos($controller, ':') === FALSE) {
if (function_exists($controller)) {
return $controller;
}
return $this->classResolver
->getInstanceFromDefinition($controller);
}
$callable = $this->createController($controller);
if (!is_callable($callable)) {
throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable.', $path));
}
return $callable;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.