ez-php/console

Lightweight console infrastructure for PHP — command dispatcher, argument parser, and colored output helpers

Maintainers

Package info

github.com/ez-php/console

pkg:composer/ez-php/console

Statistics

Installs: 46

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

0.2.0 2026-03-15 03:47 UTC

This package is auto-updated.

Last update: 2026-03-15 04:17:47 UTC


README

Lightweight console infrastructure for PHP — command dispatcher, argument parser, and colored output helpers.

Installation

composer require ez-php/console

Usage

Defining a command

use EzPhp\Console\CommandInterface;
use EzPhp\Console\Input;
use EzPhp\Console\Output;

class GreetCommand implements CommandInterface
{
    public function getName(): string { return 'greet'; }
    public function getDescription(): string { return 'Greet someone'; }
    public function getHelp(): string { return 'Usage: ez greet <name>'; }

    public function handle(array $args): int
    {
        $input = new Input($args);
        $name = $input->argument(0) ?? 'World';
        Output::success("Hello, $name!");
        return 0;
    }
}

Running the console

use EzPhp\Console\Console;

$console = new Console([new GreetCommand()]);
exit($console->run($argv));

Output helpers

Output::line('plain text');
Output::info('informational message');   // blue
Output::success('it worked!');           // green
Output::warning('be careful');           // yellow
Output::error('something failed');       // red (stderr)
Output::colorize('custom', 35);          // magenta

Parsing arguments

$input = new Input(['foo', '--name=Alice', '--verbose']);

$input->argument(0);          // 'foo'
$input->option('name');       // 'Alice'
$input->option('missing', 'default'); // 'default'
$input->hasFlag('verbose');   // true

License

MIT