ControllerResolver::createController

protected ControllerResolver::createController($controller)

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.

Overrides ControllerResolver::createController

File

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

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) {
    list($class_or_service, $method) = explode(':', $controller, 2);
  }
  // Controller in the class::method notation.
  elseif (strpos($controller, '::') !== FALSE) {
    list($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 array($controller, $method);
}
doc_Drupal
2016-10-29 08:58:58
Comments
Leave a Comment

Please login to continue.