juststeveking/laravel-business-process
Composer 安装命令:
composer require juststeveking/laravel-business-process
包简介
Laravel Business Process is a simple and clean way to run business process using a Laravel Pipeline, in a structured and type-safe way.
README 文档
README
Laravel Business Process is a simple and clean way to run business process using a Laravel Pipeline, in a structured and type-safe way.
This package is inspired by the tutorial I wrote for Laravel News Going Past Actions in Laravel.
Installation
composer require juststeveking/laravel-business-process
Usage
To get started with this package, all you need to do is create a new process class:
use JustSteveKing\BusinessProcess\Process; final class PurchaseProduct extends Process { protected array $tasks = [ CheckStockLevel::class, ProcessOrder::class, DecreaseStockLevel::class, NotifyWarehouse::class, EmailCustomer::class, ]; }
Our process class registers the tasks that need to be completed for this process to run, each task must implement the TaskContract interface that comes with this package.
use JustSteveKing\BusinessProcess\Contracts\TaskContract; final class CheckStockLevel implements TaskContract { public function __invoke(ProcessPayload $payload, Closure $next): mixed { // perform your logic here with the passed in payload. return $next($payload); } }
Your tasks are standard classes that the Pipeline class from Laravel would expect.
The payload is a class that implements ProcessPayload interface, signalling that it is a payload for a process. They are simple plain old PHP classes with no requirements to add methods.
use JustSteveKing\BusinessProcess\Contracts\ProcessPayload; final class PurchaseProductPayload implements ProcessPayload { public function __construct( // add whatever public properties you need here public int $product, public int $user, public int $order, ) {} }
Finally, we can call this process within our controller/job/cli wherever you need to.
final class PurchaseController { public function __construct( private readonly PurchaseProduct $process, ) {} public function __invoke(PurchaseRequest $request, int $product): JsonResponse { try { $this->process->run( payload: $request->payload(), ); } catch (Throwable $exception) { // Handle exception } // return response. } }
Testing
To run the test:
composer run test
Credits
LICENSE
The MIT License (MIT). Please see License File for more information.
juststeveking/laravel-business-process 适用场景与选型建议
juststeveking/laravel-business-process 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.69k 次下载、GitHub Stars 达 66, 最近一次更新时间为 2023 年 04 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 juststeveking/laravel-business-process 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 juststeveking/laravel-business-process 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.69k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 66
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-27