junty / junty-taskrunner
Junty 的任务运行器。
v0.2.2
2016-04-07 19:39 UTC
Requires
- doctrine/collections: ^1.3
- symfony/console: ^3.0
Requires (Dev)
- phpunit/phpunit: ^5.2
This package is not auto-updated.
Last update: 2024-09-26 01:15:18 UTC
README
Junty 任务运行器组件。
安装
$ composer require junty/junty-taskrunner
使用
基本使用
<?php require 'vendor/autoload.php'; use Junty\TaskRunner\Runner\Runner; $runner = new Runner(); $runner->task('say_hello', function () { echo 'hello!'; }); $runner->my_task_2 = function () { // ... }; $runner->group('tests', function () { $this->task('tests_for_users', function () { // ... }); $this->task('tests_for_admins', function () { // ... }); }); $runner->run(); // Runs all registred tasks
方法
task
使用 Junty\TaskRunner\Task\TaskInterface
或可调用的对象创建任务。
$runner->task('my_task', function () {}); // or $runner->task(new MyTask());
group
使用 Junty\TaskRunner\Task\GroupInterface
或可调用的对象创建一组任务。
$runner->group('my_group', function () { $this->task('my_task_from_group_1', function () {}); // Another tasks });
| 一组任务和任务不能有相同的名称!
order
对任务和组执行顺序进行排序。
$runner->order('my_group', 'my_task', 'my_group_2');
run
运行所有任务和组。
$runner->run();
runTask
运行单个已注册的任务或 TaskInterface
的实例。
$runner->runTask('my_registred_task'); // or $runner->runTask(new MyTask());
runGroup
运行单个已注册的组或 GroupInterface
的实例。
$runner->runGroup('my_registred_group'); // or use Junty\TaskRunner\Task\Group; $runner->runGroup(new class() extends Group { public function __construct() { } public function getName() : string { return 'my_group'; } public function task($task, callable $task = null) { } public function getTasks() : TaskCollection { $collection = new TaskCollection(); $collection->set(new MyTask()); $collection->set(new MyOtherTask()); return $collection; } });