Documentation

Action
in package

This represents an action-able route.

After finding a match, this object is produced. It contains the source elements (method, path, rule) and target elements (target, args).

The router and actions don't require the 'target' to be callable. Given that 9/10 the targets are indeed callable, this class include a bunch of helpers for that use-case.

Table of Contents

Properties

$args  : array<string|int, string>
The path arguments parsed from the path + rule.
$method  : string
The HTTP verb, like GET/POST/etc.
$path  : string
The Request URI.
$rule  : string
The rule pattern that matched.
$target  : mixed
The route target.

Methods

__construct()  : mixed
createController()  : object|null
Create the controller instance.
invoke()  : mixed
Call the target.
isCallable()  : bool
Is the 'target' callable?
isController()  : bool
The target is for a matching controller.

Properties

$args

The path arguments parsed from the path + rule.

public array<string|int, string> $args

$method

The HTTP verb, like GET/POST/etc.

public string $method

$path

The Request URI.

public string $path

$rule

The rule pattern that matched.

public string $rule

$target

The route target.

public mixed $target

Could be any, but typically a callable like [class, method].

Methods

__construct()

public __construct(array<string, mixed> $config) : mixed
Parameters
$config : array<string, mixed>

createController()

Create the controller instance.

public createController(array<string|int, mixed> $args) : object|null

This doesn't assert the controller type, first use isController().

Parameters
$args : array<string|int, mixed>

constructor arguments

Return values
object|null

invoke()

Call the target.

public invoke([object|null $instance = null ][, string|null $proxy = null ]) : mixed

This doesn't execute the isCallable() check. You must do this before calling this method.

Optionally provide an 'instance' of a 'controller' class to call methods. Again, you must call the isController() check.

Parameters
$instance : object|null = null
$proxy : string|null = null

method name (given a controller instance)

isCallable()

Is the 'target' callable?

public isCallable() : bool

However, this doesn't mean that one can invoke the property directly. Use the invoke() helper and provide an 'instance' object.

Return values
bool

isController()

The target is for a matching controller.

public isController(object|class-string $controller) : bool
Parameters
$controller : object|class-string
Return values
bool
On this page

Search results