HelpTask
Print a task's usage through cli help <task>.
cli help <task> forwards to <task> help for any task in the current module namespace, including application tasks this class does not list, so applications only replace $cliDoc to list their own tasks. A task whose handler class does not exist is forwarded to router.notFound, which reports Error: 404 - Not Found and exits with status 1. The cli role needs this task's actions (['*']) and the target task's help action.
- Full name:
\PhalconKit\Modules\Cli\Tasks\HelpTask - Parent class:
\PhalconKit\Modules\Cli\Task
Properties
cliDoc
public string $cliDoc
Methods
shouldParseUsage
Never parse help <task> with this task's usage.
protected shouldParseUsage(): bool
The task name is the action, so parsing would reject every task that $cliDoc does not list before it could be forwarded.
__call
Forward cli help <task> to <task> help for tasks without a method here.
public __call(string $method, array<array-key,mixed> $arguments): null
The dispatcher resolves help <task> to the <task>Action method; any name not declared on this class reaches this method and is forwarded.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$method | string | Undefined method name, such as reportAction. |
$arguments | array | Ignored dispatcher arguments. |
Throws:
When $method is not an action name. - BadMethodCallException if there is an error during the forwarding process - Exception
forwardToTaskHelp
Forward to <task> help, or to router.notFound for an unknown task.
protected forwardToTaskHelp(string $task): void
The handler class is resolved like the dispatcher does: the current namespace, the camelized task name, and the handler suffix.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$task | string | Dashed task name, such as data-life-cycle. |
Throws:
if there is an error during the forwarding process - Exception
buildAction
Build Action
public buildAction(): void
This method executes the build action by forwarding the request to the build task's help action.
Throws:
if there is an error during the forwarding process - Exception
cronAction
Cron Action
public cronAction(): void
This method executes the cron action by forwarding the request to the cron task's help action.
Throws:
if there is an error during the forwarding process - Exception
cacheAction
Cache Action
public cacheAction(): void
This method executes the cache action by forwarding the request to the cache task's help action.
Throws:
if there is an error during the forwarding process - Exception
databaseAction
public databaseAction(): void
dataLifeCycleAction
public dataLifeCycleAction(): void
scaffoldAction
public scaffoldAction(): void
tsScaffoldAction
public tsScaffoldAction(): void
userAction
public userAction(): void
Inherited methods
beforeExecuteRoute
Parse task-specific arguments and options with this task's cliDoc.
public beforeExecuteRoute(): void
Bootstrap already parsed the global options (--format, --quiet, --debug, ...) and stored them as named dispatcher parameters. The task parser therefore receives only the module, task, action, and positional tokens, so global options never reach a task usage string that does not declare them. Parsed task values are stored as camelCase dispatcher parameters, for example --password-stdin becomes passwordStdin.
Long options that Docopt parsed (--force, --table=<table>, --table <table>) are then removed from the positional action arguments, so cli scaffold models --force calls the action without a "--force" argument. Other positional tokens, including named Docopt arguments such as <key>, are kept in order.
Invalid task arguments make Docopt print the task usage and exit with a non-zero status. Parsing is skipped when shouldParseUsage() returns false, which it does for the help action.
shouldParseUsage
Whether beforeExecuteRoute() should parse the dispatch with cliDoc.
protected shouldParseUsage(): bool
Returns false for the help action, and for the default main action when the task keeps this class's mainAction() (which only prints the usage). phalcon-kit cli <task> help and phalcon-kit cli <task> then print the usage and exit with status 0 even when the usage does not declare those commands. Override it in tasks that are only reached by dispatcher forwards, or that parse their own arguments.
removeParsedOptionTokens
Remove long-option tokens that Docopt accepted from positional arguments.
protected removeParsedOptionTokens(list $tokens, array<array-key,mixed> $parsed): list
A token is removed when it is --name or --name=value and --name is a key of the Docopt result. For --name value, the following token is removed too when Docopt returned a string value for that option. A bare -- ends option processing: it and every later token are kept, matching Docopt's <params> list. Short options and unknown tokens are kept unchanged.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$tokens | list | Positional tokens after the action. |
$parsed | array | Docopt result keyed by usage name. |
getTaskArgv
Build the argument vector parsed by the task-level Docopt usage.
protected getTaskArgv(): list<string>
The vector is rebuilt from the dispatcher instead of $_SERVER['argv']: [module, task, action, ...positional tokens]. Positional tokens are the integer-keyed dispatcher parameters that Bootstrap left after consuming its global options; named parameters such as format or quiet are excluded.
getPositionalParameters
Return the integer-keyed dispatcher parameters in argument order.
protected getPositionalParameters(): list
These are the tokens after the action that Bootstrap did not consume as global options.
helpAction
public helpAction(): void
mainAction
public mainAction(): ?array
afterExecuteRoute
Handle rest response automagically
public afterExecuteRoute(\Phalcon\Cli\Dispatcher $dispatcher): void
Parameters:
| Parameter | Type | Description |
|---|---|---|
$dispatcher | \Phalcon\Cli\Dispatcher |
Throws:
normalizeCliPayload
Normalize values before CLI output serializers see them.
protected normalizeCliPayload(mixed $payload): mixed
Phalcon message objects are useful inside the framework but are opaque for JSON automation. This helper recursively converts them into scalar arrays while leaving other payload values unchanged.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$payload | mixed |
normalizeCliMessages
Normalize a list of model messages and optionally add a fallback entry.
protected normalizeCliMessages(iterable $messages, ?string $fallbackMessage = null): list<array{message: string, field: string|null, type: string|null, code: int|null}>
Parameters:
| Parameter | Type | Description |
|---|---|---|
$messages | iterable | Messages returned by a model or resultset. |
$fallbackMessage | ?string |