Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ControllerResolver.php

function ControllerResolver::createController

Returns a callable for the given controller.

Throws

\InvalidArgumentException When the controller cannot be created

1 call to ControllerResolver::createController()
ControllerResolver::getController in vendor/symfony/http-kernel/Controller/ControllerResolver.php

File

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

Class

ControllerResolver
This implementation uses the '_controller' request attribute to determine the controller to execute.

Namespace

Symfony\Component\HttpKernel\Controller

Code

protected function createController(string $controller) : callable {
    if (!str_contains($controller, '::')) {
        $controller = $this->instantiateController($controller);
        if (!\is_callable($controller)) {
            throw new \InvalidArgumentException($this->getControllerError($controller));
        }
        return $controller;
    }
    [
        $class,
        $method,
    ] = explode('::', $controller, 2);
    try {
        $controller = [
            $this->instantiateController($class),
            $method,
        ];
    } catch (\Error|\LogicException $e) {
        try {
            if ((new \ReflectionMethod($class, $method))->isStatic()) {
                return $class . '::' . $method;
            }
        } catch (\ReflectionException) {
            throw $e;
        }
        throw $e;
    }
    if (!\is_callable($controller)) {
        throw new \InvalidArgumentException($this->getControllerError($controller));
    }
    return $controller;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal