You are here

public function ControllerResolver::getController in Zircon Profile 8.0

Same name in this branch
  1. 8.0 vendor/symfony/http-kernel/Controller/ControllerResolver.php \Symfony\Component\HttpKernel\Controller\ControllerResolver::getController()
  2. 8.0 core/lib/Drupal/Core/Controller/ControllerResolver.php \Drupal\Core\Controller\ControllerResolver::getController()
Same name and namespace in other branches
  1. 8 vendor/symfony/http-kernel/Controller/ControllerResolver.php \Symfony\Component\HttpKernel\Controller\ControllerResolver::getController()

This method looks for a '_controller' request attribute that represents the controller name (a string like ClassName::MethodName).

Overrides ControllerResolverInterface::getController

1 method overrides ControllerResolver::getController()
ControllerResolver::getController in core/lib/Drupal/Core/Controller/ControllerResolver.php
This method looks for a '_controller' request attribute that represents the controller name (a string like ClassName::MethodName).

File

vendor/symfony/http-kernel/Controller/ControllerResolver.php, line 46

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)) {
    return $controller;
  }
  if (is_object($controller)) {
    if (method_exists($controller, '__invoke')) {
      return $controller;
    }
    throw new \InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.', get_class($controller), $request
      ->getPathInfo()));
  }
  if (false === strpos($controller, ':')) {
    if (method_exists($controller, '__invoke')) {
      return $this
        ->instantiateController($controller);
    }
    elseif (function_exists($controller)) {
      return $controller;
    }
  }
  $callable = $this
    ->createController($controller);
  if (!is_callable($callable)) {
    throw new \InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.', $controller, $request
      ->getPathInfo()));
  }
  return $callable;
}