定制 elliephp/console 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

elliephp/console

Composer 安装命令:

composer require elliephp/console

包简介

Symfony Console-based CLI component for ElliePHP microframework

README 文档

README

A lightweight PSR-11 container-aware wrapper around Symfony Console.

Installation

composer require elliephp/console

Features

  • Minimal wrapper around Symfony Console
  • Optional PSR-11 container integration
  • Framework agnostic
  • No framework-specific commands

Usage

Basic Setup (No Container)

#!/usr/bin/env php
<?php

require __DIR__ . '/vendor/autoload.php';

use ElliePHP\Console\Application;

$app = new Application();
$app->add(new YourCommand());
$app->run();

With Container (Optional)

#!/usr/bin/env php
<?php

require __DIR__ . '/vendor/autoload.php';

use ElliePHP\Console\Application;

$container = require __DIR__ . '/bootstrap/container.php';

$app = new Application($container, 'My App', '1.0.0');
$app->addCommands([
    YourCommand::class, // Resolved from container
]);
$app->run();

Creating Commands

<?php

namespace App\Console;

use ElliePHP\Console\Command\BaseCommand;
use Symfony\Component\Console\Input\InputArgument;

class GreetCommand extends BaseCommand
{
    protected function configure(): void
    {
        $this->setName('greet')
             ->setDescription('Greet someone')
             ->addArgument('name', InputArgument::OPTIONAL, 'Name to greet', 'World');
    }

    protected function handle(): int
    {
        $name = $this->argument('name');
        $this->success("Hello, {$name}!");
        return self::SUCCESS;
    }
}

Registering Commands

// Without container
$app = new Application();
$app->add(new GreetCommand());

// With container (optional)
$app = new Application($container);
$app->addCommands([
    new GreetCommand(),           // Direct instance
    AnotherCommand::class,        // Resolved from container if available
]);

$app->run();

BaseCommand Helpers

Output Methods

// Basic output
$this->success('Success message');
$this->error('Error message');
$this->info('Info message');
$this->warning('Warning message');
$this->note('Note message');
$this->comment('Comment message');

// Structured output
$this->title('Section Title');
$this->section('Subsection');
$this->table(['Header1', 'Header2'], [['Row1', 'Row2']]);

// Interactive
$name = $this->ask('What is your name?', 'Guest');
$confirm = $this->confirm('Continue?', true);
$choice = $this->choice('Select option', ['a', 'b', 'c'], 'a');

// Raw output
$this->line('A line of text');
$this->write('Text without newline');

Accessing Input

// Get arguments
$name = $this->argument('name');

// Get options
$verbose = $this->option('verbose');

Container Access

// Access container (only if provided to Application)
if ($this->container) {
    $service = $this->container->get('service');
}

Exit Codes

return self::SUCCESS;  // Command succeeded
return self::FAILURE;  // Command failed
return self::INVALID;  // Invalid usage

Quick Reference

Minimal Command

class MyCommand extends BaseCommand
{
    protected function configure(): void
    {
        $this->setName('my:command')
             ->setDescription('Does something');
    }

    protected function handle(): int
    {
        $this->success('Done!');
        return self::SUCCESS;
    }
}

Common Patterns

// Get input
$name = $this->argument('name');
$verbose = $this->option('verbose');

// Output
$this->success('Success!');
$this->error('Error!');
$this->info('Info');
$this->table(['Col1', 'Col2'], $rows);

// Interactive
$answer = $this->ask('Question?', 'default');
$confirm = $this->confirm('Continue?', true);

More Examples

See USAGE.md for comprehensive examples including:

  • Commands with arguments and options
  • Interactive commands
  • Table output
  • Container integration
  • Complete real-world examples

Requirements

  • PHP 8.1+
  • symfony/console ^6.0|^7.0
  • psr/container ^2.0

License

MIT

elliephp/console 适用场景与选型建议

elliephp/console 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 elliephp/console 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 elliephp/console 我们能提供哪些服务?
定制开发 / 二次开发

基于 elliephp/console 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 27
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-17