adrianfalleiro/slim-cli-runner
最新稳定版本:3.2.0
Composer 安装命令:
composer require adrianfalleiro/slim-cli-runner
包简介
Run command line tasks for Slim PHP
README 文档
README
Create and run command line tasks for the Slim PHP micro-framework
Installation
Installation
composer require adrianfalleiro/slim-cli-runner ^3.1
For Slim 3 support install version 2.6 or lower
Register Middleware
Register the middleware in middleware.php
$app->add(new adrianfalleiro\SlimCliRunner\CliRunner::class);
Define, Register and run your tasks
Task definition
Tasks are classes which extend CliAction and have a public command() method.
You can inject dependencies through the class constructor.
use Psr\Http\Message\ResponseInterface as Response; use adrianfalleiro\SlimCliRunner\CliAction; use Psr\Log\LoggerInterface; class ExampleCliAction extends CliAction { public function __construct(LoggerInterface $logger) { $this->logger = $logger; } protected function action(): Response { $arg0 = $this->resolveArg(0); $this->logToConsole("arg 0 is {$arg0}"); return $this->respond(); } }
Tasks registration
Add a new key in your settings.php definitions file called commands and list your tasks.
To define a default task (For use when no command name is provided) add a new task with __default as key
return function (ContainerBuilder $containerBuilder) { // Global Settings Object $containerBuilder->addDefinitions([ 'settings' => [ ... ], 'commands' => [ '__default' => \Namespace\To\Task::class 'SampleTask' => \Namespace\To\Task::class ] ]); };
Run Tasks
There are multiple ways of doing this:
Directly via command line:
php public/index.php SampleTask arg1 arg2 arg3
Via composer:
composer.json
{
/*...*/
"config": {
"process-timeout" : 0
},
"scripts": {
/*...*/
"cli": "php public/index.php"
}
}
The command
composer cli SampleTask argument1 argument2 argument3
Examples
An example project can be found in the examples/ folder
统计信息
- 总下载量: 88.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 43
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-07-16