Returns the Controller instance associated with a Request.
This method looks for a '_controller' request attribute that represents the controller name (a string like ClassName::MethodName).
@api
Request $request A Request instance:
mixed|Boolean A PHP callable representing the Controller, or false if this resolver is not able to determine the controller
\InvalidArgumentException|\LogicException If the controller can't be found
Overrides ControllerResolverInterface::getController
public function getController(Request $request) {
if (!($controller = $request->attributes
->get('_controller'))) {
if (null !== $this->logger) {
$this->logger
->warning('Unable to look for the controller as the "_controller" parameter is missing');
}
return false;
}
if (is_array($controller) || is_object($controller) && method_exists($controller, '__invoke')) {
return $controller;
}
if (false === strpos($controller, ':')) {
if (method_exists($controller, '__invoke')) {
return new $controller();
}
elseif (function_exists($controller)) {
return $controller;
}
}
$callable = $this
->createController($controller);
if (!is_callable($callable)) {
throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable.', $request
->getPathInfo()));
}
return $callable;
}