function ControllerResolver::createController

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Controller/ControllerResolver.php \Drupal\Core\Controller\ControllerResolver::createController()

Returns a callable for the given controller.

Parameters

string $controller: A Controller string.

Return value

mixed A PHP callable.

Throws

\LogicException If the controller cannot be parsed.

\InvalidArgumentException If the controller class does not exist.

1 call to ControllerResolver::createController()
ControllerResolver::getControllerFromDefinition in core/lib/Drupal/Core/Controller/ControllerResolver.php
Returns the Controller instance with a given controller route definition.

File

core/lib/Drupal/Core/Controller/ControllerResolver.php, line 103

Class

ControllerResolver
ControllerResolver to enhance controllers beyond Symfony's basic handling.

Namespace

Drupal\Core\Controller

Code

protected function createController($controller) {
    // Controller in the service:method notation.
    $count = substr_count($controller, ':');
    if ($count == 1) {
        [
            $class_or_service,
            $method,
        ] = explode(':', $controller, 2);
    }
    elseif (strpos($controller, '::') !== FALSE) {
        [
            $class_or_service,
            $method,
        ] = explode('::', $controller, 2);
    }
    else {
        throw new \LogicException(sprintf('Unable to parse the controller name "%s".', $controller));
    }
    $controller = $this->classResolver
        ->getInstanceFromDefinition($class_or_service);
    return [
        $controller,
        $method,
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.