ez-php / console
Lightweight console infrastructure for PHP — command dispatcher, argument parser, and colored output helpers
0.2.0
2026-03-15 03:47 UTC
Requires
- php: ^8.5
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^13.0
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