public function ControllerResolver::getController

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

Parameters

Request $request A Request instance:

Return value

mixed|Boolean A PHP callable representing the Controller, or false if this resolver is not able to determine the controller

Throws

\InvalidArgumentException|\LogicException If the controller can't be found

Overrides ControllerResolverInterface::getController

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Controller/ControllerResolver.php, line 57

Class

ControllerResolver
ControllerResolver.

Namespace

Symfony\Component\HttpKernel\Controller

Code

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;
}