bjuppa/eloquent-state-machine 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

统计信息

  • 总下载量: 100
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-10-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固