承接 lukman-ss/console 相关项目开发

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

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

lukman-ss/console

Composer 安装命令:

composer require lukman-ss/console

包简介

A lightweight standalone PHP Console package

README 文档

README

Lukman Console Hero

A lightweight standalone PHP console package.

Requirements

  • PHP 8.2 or higher

Installation

composer require lukman-ss/console

Quick Start

<?php

declare(strict_types=1);

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

use Lukman\Console\Command;
use Lukman\Console\ConsoleApplication;
use Lukman\Console\Input;
use Lukman\Console\Output;

$app = new ConsoleApplication('My CLI', '1.0.0');

$app->command('greet', function (Input $input, Output $output): int {
    $name = $input->argument(0, 'Guest');
    $output->success('Hello ' . $name);

    return Command::SUCCESS;
}, 'Greet a user');

$exitCode = $app->run();

Commands

Create a command by extending Lukman\Console\Command:

<?php

declare(strict_types=1);

use Lukman\Console\Command;
use Lukman\Console\Input;
use Lukman\Console\Output;

final class GreetCommand extends Command
{
    protected string $name = 'greet';
    protected string $description = 'Greet a user';
    protected string $signature = 'greet {name=Guest} {--yell}';

    public function handle(Input $input, Output $output): int
    {
        $message = 'Hello ' . $input->argument(0, 'Guest');

        if ($input->option('yell', false) === true) {
            $message = strtoupper($message);
        }

        $output->writeln($message);

        return self::SUCCESS;
    }
}

Register it:

$app->add(new GreetCommand());

Input

Input parses argv into:

  • script name from argv[0]
  • command name
  • positional arguments
  • long options like --name=value and --name value
  • flags like --force
  • short flags like -v and verbosity counts like -vvv
  • --no-interaction

Output

Output writes to stdout and stderr. Memory streams can be passed for testing.

$stdout = fopen('php://memory', 'r+');
$stderr = fopen('php://memory', 'r+');

$output = new Output($stdout, $stderr, decorated: false);
$output->writeln('ok');
$output->errorLine('error');

Built-in Commands

ConsoleApplication registers list and help automatically unless user commands with those names already exist.

php bin/console list
php bin/console help greet

Running without a command uses list.

Testing Commands

CommandTester is framework-free and captures stdout, stderr, and exit code.

use Lukman\Console\Testing\CommandTester;

$tester = new CommandTester($app);
$exitCode = $tester->run(['greet', 'Lukman']);

$stdout = $tester->output();
$stderr = $tester->errorOutput();

Tests

composer test

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固