soap/laravel-workflow-process
Composer 安装命令:
composer require soap/laravel-workflow-process
包简介
Provides Laravel workflow guards using Symfony expression and related objects
关键字:
README 文档
README
Using Zerodahero's Laravel Workflow (based on Symfony Workflow) to handle state-transition workflow is great. However, coding transition guards in events is hard. This package provides a simple way; you can add Symfony Expression Language as a transition guard for each transition. This configuration must be provided in transition metadata using the 'guard' key. The package subscribes for all workflows' transition guard events and uses the provided Symfony Expression Language to allow or block the transition.
| Laravel vesion | Package version |
|---|---|
| 10.x, 11.x, 12.x | 1.x |
Support me
Any recommendation or pull request is welcome. It is great if you sponsor me if you find my work valuable.
Installation
You can install the package via composer:
composer require soap/laravel-workflow-process
You can publish the config file with:
php artisan vendor:publish --tag="workflow-process-config"
This is the contents of the published config file:
return [ 'custom_functions' => [ // 'function_name' => [ // 'compiler' => function () { return 'true'; }, // 'evaluator' => function (array $variables) { return true; }, // ], // 'function_name' => 'App\CustomGuardFunction', // 'authenicated' => \Soap\LaravelWorkflowProcess\GuardFunctions\Authenticated::class, 'authenticated' => [ 'compiler' => function ($guard = 'web') { return sprintf('authenticated("%s")', $guard); }, 'evaluator' => function (array $variables, $guard = 'web') { // This allows checking a specific guard (e.g., 'web', 'api', etc.) return auth()->guard($guard)->check(); }, ], ], ];
Usage
Task that you have to do is providing guard configuration like the following example. This is in laravel-workflow 's configuration file (config/workflow.php). If you want to store workflow configuration in database, please visit my Laravel Workflow Loader package.
// file config/workflow.php use ZeroDaHero\LaravelWorkflow\MarkingStores\EloquentMarkingStore; return [ 'blogPost' => [ 'type' => 'workflow', 'supports' => [App\Models\BlogPost::class], 'marking_store' => [ 'property' => 'state', 'type' => 'single_state', 'class' => EloquentMarkingStore::class, ], 'places' => ['draft', 'pending_for_review', 'approved', 'rejected', 'published', 'archived'], 'transitions' => [ 'submit' => [ 'from' => 'draft', 'to' => 'pending_for_review', 'metadata' => [ 'guard' => 'authenticated and subject.isOwnedBy(user)', ], ], 'approve' => [ 'from' => 'pending_for_review', 'to' => 'approved', ], 'reject' => [ 'from' => 'pending_for_review', 'to' => 'rejected', ], 'publish' => [ 'from' => 'approved', 'to' => 'published', ], 'archive' => [ 'from' => ['draft', 'rejected'], 'to' => 'archived', ], ], ] ];
Currenty these variables/objects were injected into Symfony Expression Language.
- "subject" is the Eloquent model which is subject of a workflow
- "user" is authenticated user.
- "authenticated" boolean, true if user was authenticated. You can
So you can call any method on the injected object. So you can assign guard as authenticated and subject.isPaid(), where your model has method isPaid().
Add your own guard functions
You can add your own guard function in two way. The first one is inline in configuration file. The second way is define your GuardFunction class by implement GuardFunctionInterface and point to it in the configuration. You can see example in the provided configuration file.
You can also overide the GuardEvaluator class in Application Service Provider with your own class.
Todo
I have a plan to provide document role for user. For example, some users may be assign as "reviewer" or "approver" for Eloquent model. So we can use something like subject.hasActorRole('reviewer') or subject.canBeReviewedBy(user). Any suggestion is welcome.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
soap/laravel-workflow-process 适用场景与选型建议
soap/laravel-workflow-process 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.16k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 09 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「language」 「laravel」 「expression」 「transition」 「guard」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 soap/laravel-workflow-process 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 soap/laravel-workflow-process 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 soap/laravel-workflow-process 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Easy to use i18n translation PHP class for multi-language websites
Package for convenient work with Laravel's localization features
Store your language lines in the database, yaml or other sources
The bundle for easy using json-rpc api on your project
Set Links with a specific language parameter
统计信息
- 总下载量: 1.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-26