iquety/console

PHP终端例程实现工具包

维护者

详细信息

github.com/iquety/console

源代码

问题

安装量: 1,392

依赖者: 3

建议者: 0

安全性: 0

星标: 0

关注者: 0

分支: 0

开放问题: 0

类型:工具

v2.1.1 2024-09-16 14:21 UTC

This package is auto-updated.

Last update: 2024-09-16 14:42:22 UTC


README

PHP Version License Codacy Badge Codacy Badge

概要

此仓库包含在PHP应用程序中轻松实现终端例程管理器所需的功能。

composer require iquety/console

有关详细信息,请参阅文档概要

如何使用

1. 创建例程

基于抽象类Iquety\Console\Routine实现一个名为"my-routine"的例程

class MyRoutine extends Routine
{
    protected function initialize(): void
    {
        $this->setName("my-routine");
        $this->addOption(
            new Option('-r', '--read', 'Read a text file', Option::REQUIRED)
        );
    }

    protected function handle(Arguments $arguments): void
    {
        $this->info("Hello");
    }
}

2. 创建脚本

创建一个文件,例如命名为"myconsole",并添加以下内容

#!/bin/php
<?php
include __DIR__ . "/vendor/autoload.php";

array_shift($argv);

$terminal = new Iquety\Console\Terminal("/root/of/super/application");
$terminal->loadRoutinesFrom("/directory/of/routines");
$terminal->run($argv);

3. 运行脚本

./myconsole my-routine -r
# will display: Hello
./myconsole my-routine --help
# will display:
#
# Routine: my-routine
# Run the 'my-routine' routine
# 
# How to use:
# ./myconsole my-routine [options]
# 
# Options:
# -h, --help   Display routine help
# -r, --read   Read a text file
./myconsole --help
# will display:
#
# How to use:
# ./myconsole routine [options] [arguments]
# 
# Options:
# -h, --help   Display routine help
#
# Available routines:
# help           Display routine help
# my-routine     Run the 'my-routine' routine

特点

  • 适用于PHP 8.3或更高版本;
  • 编码遵循最佳实践和质量标准;
  • 文档完善且适用于IDE;
  • 采用TDD(测试驱动开发);
  • 使用PHPUnit进行单元测试;
  • 用❤️ & ☕制作。

致谢

Ricardo Pereira Dias