Director
in package
The director allows an application to register a command that should be able to be invoked via CLI.
Tags
Table of Contents
- exec() : int
- Executes the director, handling control to the application implementing it.
- parameters() : array<string|int, mixed>
- Return an array that describes what parameters the application expects.
Methods
exec()
Executes the director, handling control to the application implementing it.
public
abstract exec(array<string|int, mixed> $parameters, CLIParameters $arguments) : int
Parameters
- $parameters : array<string|int, mixed>
-
The array of parameters parsed from the input, using the data provided by parameters()
- $arguments : CLIParameters
-
The raw arguments read from the process
Return values
int —The return code
parameters()
Return an array that describes what parameters the application expects.
public
abstract parameters() : array<string|int, mixed>
This looks something like this:
return [
'-v' => '--verbose',
'-t' => '--tag',
'--verbose' => [
'type' => 'bool',
'description' => 'Provide verbose output'
],
'--tag' => [
'required' => false,
'type' => 'string',
'description' => 'Selects which tag to use. If omitted, the script will ask for a tag'
]
];
The array may contain any of the following: a string or an array.
If the key contains a string, it redirects the settings to the appropriate key. In our example the '-v' can be redirected to '--verbose', but also deprecated keys can be addressed like '--debug' to '--verbose'
If the key contains an array, three keys are expected:
- Required: Indicating whether the key is required to execute the director
- Type: Allowing the system to pre-process input (arrays can be read from multiple params and ints can be type checked)
- Description: If the user requests help or a list for the parameters, they will get this.