rokke/console

Console transport adapter for the Rokke Runtime — routes CLI commands to compiled operations

Maintainers

Package info

github.com/rokke-php/console

Homepage

pkg:composer/rokke/console

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.3.0 2026-07-16 03:35 UTC

This package is auto-updated.

Last update: 2026-07-16 03:35:55 UTC


README

CI Latest Version PHP License

Console transport adapter for the Rokke Runtime — routes CLI commands to compiled operations exactly as rokke/http routes HTTP requests.

What this is

rokke/console is the CLI transport layer for the Rokke Framework. It scans a directory for classes annotated with #[Command('name')], compiles them into a flat CommandRegistry at build time, and at runtime parses argv tokens into an OperationContext that flows through the same ExecutionEngine as HTTP operations.

There is no Swoole dependency — ConsoleHost::run() uses plain PHP I/O. The build pipeline (ConsoleKernel) mirrors HttpKernel precisely: capability → model builder pass → descriptor → compiler → artifact → host.

Installation

composer require rokke/console

Requires: PHP ≥ 8.4, rokke/runtime ^0.15.0

Usage

1. Create a command handler

use Rokke\Console\Attribute\Command;
use Rokke\Console\Attribute\Option;

#[Command('users:create')]
final class CreateUserCommand
{
    public function __invoke(
        #[Option] string $name,
        #[Option] int $age = 0,
    ): string {
        return "Created user {$name} (age {$age})";
    }
}

2. Boot the kernel and run

use Rokke\Console\ConsoleKernel;
use Rokke\Console\ConsoleModule;

(new ConsoleKernel())
    ->register(new ConsoleModule(
        directory: __DIR__ . '/Commands',
        namespace: 'App\\Commands',
    ))
    ->build()
    ->run(); // reads $_SERVER['argv'] automatically

3. Invoke from the terminal

php app users:create --name=Fernando --age=28
# Created user Fernando (age 28)

API reference

Attributes

Attribute Target Purpose
#[Command('name')] class Marks an invokable class as a CLI command
#[Option] parameter Resolves a handler parameter from --key=value or --flag
#[Option(short: 'n')] parameter Also accepts -n value short form

Key classes

Class Purpose
ConsoleKernel Build entry point — discovers, compiles, produces ConsoleHost
ConsoleModule Module that wires ConsoleDirectoryDiscoveryProvider into the graph
ConsoleHost Runtime entry point — parses argv, dispatches via ExecutionEngine
CommandRegistry Compiled artifact — flat map of name → operationId
ConsoleContextFactory Parses raw argv tokens into OperationContext

When to use

Use rokke/console when you need to route CLI commands through the same compiled operation pipeline as HTTP handlers — sharing middleware, validation, and result plans between HTTP and CLI surfaces.

For one-off scripts with no need for the operation pipeline, use plain PHP directly.

Stability

0.x — API may evolve as the framework matures. No breaking changes within a minor version.

License

MIT