class ControllerResolver extends ControllerResolver implements ControllerResolverInterface (View source)

ControllerResolver to enhance controllers beyond Symfony's basic handling.

It adds two behaviors:

  • When creating a new object-based controller that implements ContainerAwareInterface, inject the container into it. While not always necessary, that allows a controller to vary the services it needs at runtime.

  • By default, a controller name follows the class::method notation. This class adds the possibility to use a service from the container as a controller by using a service:method notation (Symfony uses the same convention).

Properties

protected ClassResolverInterface $classResolver

The class resolver.

protected HttpMessageFactoryInterface $httpMessageFactory

The PSR-7 converter.

Methods

__construct(HttpMessageFactoryInterface $http_message_factory, ClassResolverInterface $class_resolver)

Constructs a new ControllerResolver.

mixed|bool
getControllerFromDefinition(mixed $controller, $path = '')

Returns the Controller instance with a given controller route definition.

getController(Request $request)

{@inheritdoc}

mixed
createController(string $controller)

Returns a callable for the given controller.

Details

__construct(HttpMessageFactoryInterface $http_message_factory, ClassResolverInterface $class_resolver)

Constructs a new ControllerResolver.

Parameters

HttpMessageFactoryInterface $http_message_factory

The PSR-7 converter.

ClassResolverInterface $class_resolver

The class resolver.

mixed|bool getControllerFromDefinition(mixed $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')

$path

Return Value

mixed|bool

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

Exceptions

LogicException

getController(Request $request)

{@inheritdoc}

Parameters

Request $request

protected mixed createController(string $controller)

Returns a callable for the given controller.

Parameters

string $controller

A Controller string.

Return Value

mixed

A PHP callable.

Exceptions

LogicException
InvalidArgumentException