ControllerResolver::getControllerFromDefinition

public ControllerResolver::getControllerFromDefinition($controller, $path = '')

Returns the Controller instance with a given controller route definition.

As several resolvers can exist for a single application, a resolver must return false when it is not able to determine the controller.

Parameters

mixed $controller: The controller attribute like in $request->attributes->get('_controller')

Return value

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

Throws

\InvalidArgumentException|\LogicException Thrown if the controller can't be found.

Overrides ControllerResolverInterface::getControllerFromDefinition

See also

\Symfony\Component\HttpKernel\Controller\ControllerResolverInterface::getController()

File

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

Class

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

Namespace

Drupal\Core\Controller

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public function getControllerFromDefinition($controller, $path = '') {
  if (is_array($controller) || (is_object($controller) && method_exists($controller, '__invoke'))) {
    return $controller;
  }
 
  if (strpos($controller, ':') === FALSE) {
    if (function_exists($controller)) {
      return $controller;
    }
    elseif (method_exists($controller, '__invoke')) {
      return new $controller();
    }
  }
 
  $callable = $this->createController($controller);
 
  if (!is_callable($callable)) {
    throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable.', $path));
  }
 
  return $callable;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.