PHP Class lithium\console\Dispatcher
The console dispatcher is responsible for accepting requests from scripts called from the command
line, and executing the appropriate
Command class(es). The
run() method accepts an instance
of
lithium\console\Request, which encapsulates the console environment and any command-line
parameters passed to the script.
Dispatcher then invokes
lithium\console\Router to determine
the correct
Command class to invoke, and which method should be called.
Show file
Open project: unionofrad/lithium
Class Usage Examples
Protected Properties
Property |
Type |
Description |
|
$_classes |
array |
Class must implement a parse() method, which must return an array with (at a minimum)
'command' and 'action' keys. |
|
$_rules |
array |
Each key in the array represents a 'rule'; if a key that matches the rule is present (and
not empty) in a route, (i.e. the result of lithium\console\Router::parse()) then the rule's
value will be applied to the route before it is dispatched. When applying a rule, any array
elements array elements of the flag which are present in the route will be modified using a
lithium\util\String::insert()-formatted string. |
|
Public Methods
Method |
Description |
|
applyRules ( array $params ) : array |
Attempts to apply a set of formatting rules from $_rules to a $params array. |
|
config ( array $config = [] ) : array |
Used to set configuration parameters for the Dispatcher. |
|
run ( object $request = null, array $options = [] ) : object |
Dispatches a request based on a request object (an instance of lithium\console\Request). |
|
Protected Methods
Method Details
_call()
protected static method
This method is responsible for calling a $callable command and returning its result.
protected static _call ( string $callable, string $request, string $params ) : mixed |
$callable |
string |
The callable command. |
$request |
string |
The associated `Request` object. |
$params |
string |
Additional params that should be passed along. |
return |
mixed |
Returns the result of the called action, typically `true` or `false`. |
_callable()
protected static method
Determines which command to use for current request.
protected static _callable ( object $request, array $params, array $options ) : class |
$request |
object |
An instance of a `Request` object. |
$params |
array |
Request params that can be accessed inside the filter. |
$options |
array |
|
return |
class |
lithium\console\Command Returns the instantiated command object. |
applyRules()
public static method
Each formatting rule is applied if the key of the rule in $_rules is present and not empty
in $params. Also performs sanity checking against $params to ensure that no value
matching a rule is present unless the rule check passes.
public static applyRules ( array $params ) : array |
$params |
array |
An array of route parameters to which rules will be applied. |
return |
array |
Returns the `$params` array with formatting rules applied to array values. |
config()
public static method
Used to set configuration parameters for the Dispatcher.
public static config ( array $config = [] ) : array |
$config |
array |
Optional configuration params. |
return |
array |
If no parameters are passed, returns an associative array with the
current configuration, otherwise returns null. |
run()
public static method
If $request is null, a new request object is instantiated based on the value of the
'request' key in the $_classes array.
public static run ( object $request = null, array $options = [] ) : object |
$request |
object |
An instance of a request object with console request information. If
`null`, an instance will be created. |
$options |
array |
|
return |
object |
The command action result which is an instance of `lithium\console\Response`. |
Property Details
$_classes protected static property
Class must implement a parse() method, which must return an array with (at a minimum)
'command' and 'action' keys.
protected static array $_classes |
return |
array |
|
$_rules protected static property
Each key in the array represents a 'rule'; if a key that matches the rule is present (and
not empty) in a route, (i.e. the result of lithium\console\Router::parse()) then the rule's
value will be applied to the route before it is dispatched. When applying a rule, any array
elements array elements of the flag which are present in the route will be modified using a
lithium\util\String::insert()-formatted string.
protected static array $_rules |
return |
array |
|