bjuppa/eloquent-state-machine
Composer 安装命令:
composer require bjuppa/eloquent-state-machine
包简介
Finite state machines for Laravel Eloquent models
README 文档
README
This package allows you to treat a Laravel Eloquent model and its relationships as extended state in a hierarchical state machine.
The philosophy that sets this package apart from most other state machine implementations is that behavior is declared in code in classes representing states and events, and the model itself determines the current state. There is no overall configuration of the state machine's graph. The current state handles incoming events and transitions the model into another state.
- Every state and event is represented by a PHP class, extending a relevant base class.
- A state declares the superstate (composite or root) it belongs too.
- Events are dispatched to the current state of the model.
- Event handling happens within database transactions with pessimistic row-locks.
- The current state evaluates an incoming event (guards) and may initiate a transition to another (named) state.
- Events not explicitly handled by the current state will bubble up the state branch.
- States have entry and exit actions and events have actions that manipulate the model during a transition.
- Side effects can be deferred for processing to after the transition is completed.
- Any anomalies during transitions throws exceptions, triggering transaction rollback.
Project status
I, Björn Nilsved, created this package back in 2020 for a Laravel app that has been in production since 2021. The development process of the state machine functionality was rather exploratory and focused on the needs of that specific app. As the state machine API, base classes, etc were very much in flux, I wrote specific tests in the app itself, and held off writing generic tests for the package until the structure had stabilised. Of course, once the API was stable and the app was deployed I never got around to writing those tests or documentation for the package as planned...
For my own needs this situation is fine, I'm confident in the test suite of my app.
Should others show interest in this package I'd be willing to put some effort in to set up proper testing and documentation for release of a stable 1.0 version.
Please get in touch if this is something you'd like to see happen!
Requirements
Row-level locking is only supported in MySQL / MariaDB and PostgreSQL.
Installation
You can install the package via composer:
composer require bjuppa/eloquent-state-machine
Usage
Start by drawing a statechart for your state machine, without it you will probably miss some state, transition, event or action.
Everything related to a specific state in the chart is coded directly into distinct methods of that state's PHP class.
Security
If you discover any security related issues, please email nilsved@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
bjuppa/eloquent-state-machine 适用场景与选型建议
bjuppa/eloquent-state-machine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 100 次下载、GitHub Stars 达 3, 最近一次更新时间为 2020 年 10 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「state machine」 「laravel」 「eloquent」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bjuppa/eloquent-state-machine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bjuppa/eloquent-state-machine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bjuppa/eloquent-state-machine 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Doctrine implementation of the MetaborStd (Statemachine) for PHP 8.2+
A simple state dropdown field for SilverStripe forms
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.
Automatically translate and review your content via Lokalise.
Convert and operate with FIPS codes for states, counties, etc.
统计信息
- 总下载量: 100
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-10-21