nexphant/console
CLI command framework for Nexphant applications.
Install
bash
composer require nexphant/consoleDefine a Command
Commands extend Nexphant\Console\Command and implement the execute method.
php
use Nexphant\Console\Command;
class GreetCommand extends Command
{
protected string $name = 'greet';
protected string $description = 'Greet a user';
public function execute(array $args = []): int
{
$parsed = $this->parseArgs($args);
// Retrieve arguments or options
$name = $parsed['arguments'][0] ?? 'World';
$shout = isset($parsed['options']['shout']);
$message = "Hello, {$name}!";
if ($shout) {
$message = strtoupper($message);
}
$this->output($message);
return 0; // return exit code
}
}Register Commands
You can register custom commands in the Console runtime registry:
php
use Nexphant\Console\Console;
$console = new Console();
$console->register('greet', new GreetCommand());
// Run the console application
$exitCode = $console->run($argv);
exit($exitCode);Commands can also be registered against the shared CommandRegistry used by the built-in console commands:
php
use Nexphant\Console\CommandRegistry;
$registry = new CommandRegistry();
$registry->register('greet', new GreetCommand());
$command = $registry->get('greet');
$all = $registry->all();
$exitCode = $registry->execute('greet', ['Alice']);Run
bash
php nexphant greet Alice --shoutBuilt-in Commands
Queue Commands
| Command | Description |
|---|---|
queue:work | Start queue worker process |
queue:stats | Display queue statistics |
queue:clear | Clear all pending jobs from queue |
queue:retry | Retry failed jobs |
Runtime Commands
| Command | Description |
|---|---|
runtime:status | Display runtime status and health |
runtime:metrics | Display runtime metrics |
runtime:workers | Display runtime worker lifecycle status |
runtime:health | Check runtime health |
runtime:reload | Reload runtime configuration |
runtime:stop | Stop runtime gracefully |
runtime:backends | Display selected runtime backends |
runtime:doctor | Display runtime extension status and capabilities |
Other Commands
| Command | Description |
|---|---|
optimize | Compile runtime hot path artifacts |
optimize:clear | Clear compiled runtime artifacts |
preload | Warm runtime classes for OPcache/APCu |
help | Display help information |
Output Helpers
Within a command, you can use output helpers to print messages:
php
// Standard output
$this->output('Information message');
// Error output (written to STDERR)
$this->error('Error message');Argument Parsing
Command::parseArgs() separates positional arguments and options:
bash
php nexphant queue:work default --workers=4 --quietThe parsed shape is:
php
[
'arguments' => ['default'],
'options' => [
'workers' => '4',
'quiet' => true,
],
]Expose command metadata with getName(), getDescription(), and getOptions().
