承接 ez-php/console 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ez-php/console

Composer 安装命令:

composer require ez-php/console

包简介

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

README 文档

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

Progress bars

$bar = Output::progressBar(100);
foreach ($items as $item) {
    process($item);
    $bar->advance();
}
$bar->finish();

Interactive prompts

use EzPhp\Console\Prompt;

$prompt = new Prompt();
$name   = $prompt->ask('What is your name?');
$ok     = $prompt->confirm('Continue?');
$color  = $prompt->choice('Pick a color', ['red', 'green', 'blue']);

Structured command definitions

Commands implementing HasDefinition expose typed argument and option metadata for --help rendering:

use EzPhp\Console\HasDefinition;
use EzPhp\Console\CommandDefinition;

class MyCommand implements CommandInterface, HasDefinition
{
    public function getDefinition(): CommandDefinition
    {
        return (new CommandDefinition())
            ->argument('name', 'The user name')
            ->option('force', 'f', 'Skip confirmation');
    }
    // ...
}

Command aliases

use EzPhp\Console\AliasedCommand;

$commands = [
    new AliasedCommand($app->make(MigrateCommand::class), 'db:migrate'),
];

Classes

Class Description
Console Command registry and dispatcher
CommandInterface Contract: getName, getDescription, getHelp, handle
HasDefinition Optional interface: exposes CommandDefinition for structured --help
AliasedCommand Wraps a command under a different name
Input Parses argv tokens into positional arguments and named options/flags
Output Static ANSI output helpers; table(); progressBar() factory
ProgressBar In-place terminal progress bar
Prompt Interactive prompts: ask(), confirm(), choice()
InputStreamInterface Abstraction over a readable line stream (injectable for testing)
StdinInputStream InputStreamInterface implementation reading from STDIN
CommandDefinition Fluent builder for argument + option declarations
ArgumentDefinition Value object: positional argument (name, description, required)
OptionDefinition Value object: named option (name, short alias, description)

License

MIT

统计信息

  • 总下载量: 3.95k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固