php-extended/php-workflow-object
Composer 安装命令:
composer require php-extended/php-workflow-object
包简介
A library that implements the php-extended/php-workflow-interface package
README 文档
README
A library that implements the php-extended/php-workflow-interface package
Installation
The installation of this library is made via composer and the autoloading of all classes of this library is made through their autoloader.
- Download
composer.pharfrom their website. - Then run the following command to install this library as dependency :
php composer.phar php-extended/php-workflow-object ^9
Basic Usage
Lets say you want to express the workflow of a door (which can be opened or closed). You have the following schema :
+--------+ open +--------+
| | ---------> | |
| closed | | opened |
| | <--------- | |
+--------+ close +--------+
Then, you'll have to have the following classes:
use PhpExtended\Workflow\SubjectInterface; use PhpExtended\Workflow\StateInterface; use PhpExtended\Workflow\ConditionInterface; use PhpExtended\Workflow\WorkflowBuilder;
class Door implements SubjectInterface {
public $_state = null;
public function __construct()
{
$this->_state = new Closed();
}
public function getState(WorkflowInterface $workflow) : StateInterface
{
if($workflow->getName() === 'usage')
{
return $this->_state;
}
return new Closed();
}
public function execute(TransitionInterface $transition) : StateInterface
{
if($transition->getName() === 'open')
{
return $this->_state = new Opened();
}
if($transition->getName() === 'close')
{
return $this->_state = new Closed();
}
return new Closed();
}
}
class Opened implements StateInterface; {
public function getName() : string
{
return 'opened';
}
}
class Closed implements StateInterface {
public function getName() : string
{
return 'closed';
}
}
class DoorIsClosed implements ConditionInterface {
public function isSatisfiedBy(SubjectInterface $subject) : bool
{
return $subject instanceof Door
&& $subject->getState() instanceof Closed;
}
}
class DoorIsOpened implements ICondition {
public function isSatisfiedBy(ISubject $subject) : bool
{
return $subject instanceof Door
$subject->getState() instanceof Opened;
}
}
$definition = new Definition('usage'); $opened = new Opened(); $closed = new Closed(); $open = new Transition('open', $opened, $closed); $close = new Transition('close', $closed, $opened); $workflowBuilder->addCondition('open', new DoorIsClosed()); $workflowBuilder->addTransition('close', $opened, $closed); $workflowBuilder->addCondition('close', new DoorIsOpened());
$workflow = $workflowBuilder->getWorkflow('usage');
$door = new Door(); // at instanciation, door is closed $workflow->can($door, $closed); // returns false $workflow->car($door, $opened); // returns true $workflow->perform($door, $opened); // door is now opened $workflow->can($door, $opened); // returns false $workflow->can($door, $closed); // returns true $workflow->perform($door, $closed); // door is now closed
License
MIT (See license file).
php-extended/php-workflow-object 适用场景与选型建议
php-extended/php-workflow-object 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.07k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 02 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「state」 「workflow」 「transition」 「subject」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 php-extended/php-workflow-object 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 php-extended/php-workflow-object 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 php-extended/php-workflow-object 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Workflow for NetCommons Plugin
Doctrine implementation of the MetaborStd (Statemachine) for PHP 8.2+
A simple state dropdown field for SilverStripe forms
Workflow logger
A state Machine library for business processes
Metamel Addresses is a polymorphic Laravel package, for address book management. You can add addresses to any eloquent model with ease.
统计信息
- 总下载量: 6.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-22