bpartner/tasks
Composer 安装命令:
composer require bpartner/tasks
包简介
Make callable task easy
关键字:
README 文档
README
Use this trait for easy call your task
Installation
You can install the package via composer:
composer require bpartner/tasks
Usage
Create task
namespace App\Test; use Bpartner\Tasks\Tasks; class Task extends Tasks { /** * @param \Illuminate\Support\Fluent $object #for Laravel * * @return mixed */ public function __invoke($object) { // TODO: Implement __invoke() method. } }
Use Task with CallableTrait in any class
use Illuminate\Support\Fluent; use Illuminate\Http\Request; class Controller { use CallableTrait; public function index(Request $request) { $data = new Fluent($request->all()); return $this->run(\App\Test\Tasks::class, $data); } }
Run pipeline from tasks
To start the sequence of your tasks, you must first add a trait use PipelineTaskTrait; to all tasks.
Implement handle method in task.
Anywhere in the code where the CallableTrait is used, you need to create an array from the sequence of tasks,
and call $this->runPipe($data, $pipes); method.
namespace App\Test; use Bpartner\Tasks\Tasks; use Bpartner\Tasks\PipelineTaskTrait; class Task extends Tasks { use PipelineTaskTrait; /** * @param \Illuminate\Support\Fluent $object * * @return mixed */ public function __invoke($object) { // TODO: Implement __invoke() method. } /** * @param \Illuminate\Support\Fluent $content * @param \Closure $next * * @return mixed */ public function handle(Fluent $content, Closure $next): Fluent { //Check or modify $content return $next($content); } } //---------------------------------------------- use Illuminate\Support\Fluent; use Illuminate\Http\Request; class Controller { use CallableTrait; public function index(Request $request) { $data = new Fluent($request->all()); $pipes = [ \App\Test\Task::class, \App\Test\Task2::class ]; return $this->runPipe($data, $pipes); } }
Changelog
Please see CHANGELOG for more information what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 203
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-10-18