j0hnys/trident-workflow
Composer 安装命令:
composer require j0hnys/trident-workflow
包简介
Integerate Symfony Workflow component into laravel Trident.
README 文档
README
Use the Symfony Workflow component in Laravel.
Installation
composer require j0hnys/trident-workflow
Add the Workflow facade to your facades array:
<?php ... 'Workflow' => J0hnys\TridentWorkflow\Facades\WorkflowFacade::class,
Configuration
Publish the config file
php artisan vendor:publish --provider="J0hnys\TridentWorkflow\WorkflowServiceProvider"
Configure your workflow in config/workflow.php
<?php return [ 'straight' => [ 'type' => 'workflow', 'marking_store' => [ 'type' => 'single_state', 'arguments' => ['currentPlace'] ], 'supports' => ['App\BlogPost'], 'places' => ['draft', 'review', 'rejected', 'published'], 'transitions' => [ 'to_review' => [ 'from' => 'draft', 'to' => 'review' ], 'publish' => [ 'from' => 'review', 'to' => 'published' ], 'reject' => [ 'from' => 'review', 'to' => 'rejected' ] ], ] ];
Use the WorkflowTrait inside supported classes
<?php namespace App; use Illuminate\Database\Eloquent\Model; use J0hnys\TridentWorkflow\Traits\WorkflowTrait; class BlogPost extends Model { use WorkflowTrait; }
Usage
<?php use App\BlogPost; use J0hnys\TridentWorkflow\WorkflowRegistry; $workflow_name = 'straight'; $configuration = config('workflow')[$workflow_name]; $workflow_configuration = app()->make('J0hnys\TridentWorkflow\PackageProviders\Configuration'); $workflow_configuration->setWorkflow($workflow_name, $configuration); $workflow_registry = new WorkflowRegistry($workflow_name); $post = BlogPost::find(1); $workflow = $workflow_registry->get($post); $workflow->can($post, 'publish'); // False $workflow->can($post, 'to_review'); // True $transitions = $workflow->getEnabledTransitions($post); // Apply a transition $workflow->apply($post, 'to_review'); $post->save(); // Don't forget to persist the state
Use the events
This package provides a list of events fired during a transition
J0hnys\TridentWorkflow\Events\Guard J0hnys\TridentWorkflow\Events\Leave J0hnys\TridentWorkflow\Events\Transition J0hnys\TridentWorkflow\Events\Enter J0hnys\TridentWorkflow\Events\Entered
You can subscribe to an event
<?php namespace App\Listeners; use J0hnys\TridentWorkflow\Events\GuardEvent; class BlogPostWorkflowSubscriber { /** * Handle workflow guard events. */ public function onGuard(GuardEvent $event) { /** Symfony\Component\Workflow\Event\GuardEvent */ $originalEvent = $event->getOriginalEvent(); /** @var App\BlogPost $post */ $post = $originalEvent->getSubject(); $title = $post->title; if (empty($title)) { // Posts with no title should not be allowed $originalEvent->setBlocked(true); } } /** * Handle workflow leave event. */ public function onLeave($event) {} /** * Handle workflow transition event. */ public function onTransition($event) {} /** * Handle workflow enter event. */ public function onEnter($event) {} /** * Handle workflow entered event. */ public function onEntered($event) {} /** * Register the listeners for the subscriber. * * @param Illuminate\Events\Dispatcher $events */ public function subscribe($events) { $events->listen( 'J0hnys\TridentWorkflow\Events\GuardEvent', 'App\Listeners\BlogPostWorkflowSubscriber@onGuard' ); $events->listen( 'J0hnys\TridentWorkflow\Events\LeaveEvent', 'App\Listeners\BlogPostWorkflowSubscriber@onLeave' ); $events->listen( 'J0hnys\TridentWorkflow\Events\TransitionEvent', 'App\Listeners\BlogPostWorkflowSubscriber@onTransition' ); $events->listen( 'J0hnys\TridentWorkflow\Events\EnterEvent', 'App\Listeners\BlogPostWorkflowSubscriber@onEnter' ); $events->listen( 'J0hnys\TridentWorkflow\Events\EnteredEvent', 'App\Listeners\BlogPostWorkflowSubscriber@onEntered' ); } }
Dump Workflows
Symfony workflow uses GraphvizDumper to create the workflow image. You may need to install the dot command of Graphviz
php artisan workflow:dump workflow_name --class App\\BlogPost
You can change the image format with the --format option. By default the format is png.
php artisan workflow:dump workflow_name --format=jpg
j0hnys/trident-workflow 适用场景与选型建议
j0hnys/trident-workflow 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 135 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 08 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「workflow」 「laravel」 「laravel5」 「trident」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 j0hnys/trident-workflow 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 j0hnys/trident-workflow 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 j0hnys/trident-workflow 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Workflow for NetCommons Plugin
The bundle for easy using json-rpc api on your project
Workflow logger
Approval Workflow Engine for Filament
Bundle Symfony DaplosBundle
Operational approvals engine for Laravel applications.
统计信息
- 总下载量: 135
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-08-09