Skip to content
docsv0.5.0

HandlerReference

An immutable, framework-agnostic pointer to the code a route runs: a controller class plus the method that handles the request (defaulting to `__invoke` for a single-action handler class). Serializable, so route tables can be compiled and cached; a {@see HandlerResolverInterface} turns it into a live PSR-15 request handler.

HandlerReference::__construct()

public function __construct(string $controller, string $method = '__invoke'):

Parameters

Parameters of __construct()
NameTypeDescription
$controllerclass-stringthe handler class
$methodstringthe method that handles the request

HandlerReference::action()

public static function action(string $controller): self

Reference a single-action handler class through its `__invoke` method.

Parameters

Parameters of action()
NameTypeDescription
$controllerclass-string

HandlerReference::method()

public static function method(string $controller, string $method): self

Reference a specific method on a controller class.

Parameters

Parameters of method()
NameTypeDescription
$controllerclass-string
$methodstring

HandlerReference::of()

public static function of(array $handler): self

The reference behind `[Controller::class, 'method']` — the way a route names its handler. Anything else is refused here, by shape and naming what was received: a route whose handler cannot be resolved would otherwise surface at dispatch, as a 500 to whoever asked, instead of at declaration, to whoever wrote it. Only the pair is accepted: a bare `Controller::class` for a single-action handler arrives with its first consumer in the family (greenhouse decisions/0388).

Parameters

Parameters of of()
NameTypeDescription
$handlerarray<mixed>

HandlerReference::__toString()

public function __toString(): string

Render the reference as `Controller::method`.