iquety / console
PHP终端例程实现工具包
v2.1.1
2024-09-16 14:21 UTC
Requires
- php: ^8.3.0
- iquety/security: dev-main
Requires (Dev)
- codacy/coverage: dev-master
- iquety/docmap: *
- phpmd/phpmd: @stable
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^9
- squizlabs/php_codesniffer: 3.*
README
概要
此仓库包含在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进行单元测试;
- 用❤️ & ☕制作。