Skip to content

nexphant/console ​

CLI command framework for Nexphant applications.

Install ​

bash
composer require nexphant/console

Define 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 --shout

Built-in Commands ​

Queue Commands ​

CommandDescription
queue:workStart queue worker process
queue:statsDisplay queue statistics
queue:clearClear all pending jobs from queue
queue:retryRetry failed jobs

Runtime Commands ​

CommandDescription
runtime:statusDisplay runtime status and health
runtime:metricsDisplay runtime metrics
runtime:workersDisplay runtime worker lifecycle status
runtime:healthCheck runtime health
runtime:reloadReload runtime configuration
runtime:stopStop runtime gracefully
runtime:backendsDisplay selected runtime backends
runtime:doctorDisplay runtime extension status and capabilities

Other Commands ​

CommandDescription
optimizeCompile runtime hot path artifacts
optimize:clearClear compiled runtime artifacts
preloadWarm runtime classes for OPcache/APCu
helpDisplay 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 --quiet

The parsed shape is:

php
[
    'arguments' => ['default'],
    'options' => [
        'workers' => '4',
        'quiet' => true,
    ],
]

Expose command metadata with getName(), getDescription(), and getOptions().

Released under the MIT License.