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
->warn('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;
}
}
list($controller, $method) = $this
->createController($controller);
if (!method_exists($controller, $method)) {
throw new \InvalidArgumentException(sprintf('Method "%s::%s" does not exist.', get_class($controller), $method));
}
return array(
$controller,
$method,
);
}