PHP 中的用户状态工作流引擎
我希望在 PHP 应用程序中实现用户状态/工作流程处理。
目前有:
- 基于用户的系统,具有大约 10 种不同的状态,任何用户都可以处于(启用、禁用、预注册、取消注册、删除等)
- 定义的规则,关于从哪个状态到哪个状态用户可以根据不同的系统事件进入
- 一个相当混乱(但大部分正常工作)的系统,其中充满了分散在各个地方的 IF 和 SWITCH
想要:
- 用“聪明”的状态替换当前的 IFfy 用户状态处理机器允许定义这些用户转换规则,
- 允许可视化这些定义的规则
- 通过确保用户只能处于合法状态来使系统更加安全和防弹
我的研究:
我检查了 SO 和其他地方的工作流程和状态机的 PHP 实现,有希望的候选者似乎是
- PEAR FSM http://www.indelible.org/php/FSM/guide.html
- 或 eZ componenet 工作流程 http://ezcomponents.org/docs/api/trunk/introduction_Workflow.html
我将不胜感激关于任何工作经验的评论上面的任何一个库和/或关于是否适合我需要的意见或关于其他地方寻找的提示。
I'm looking to implement user state / workflow handling in a PHP application.
Currently have:
- a user based system with around 10 different states any user can be in (enabled, disabled, pre-registered, de-registered, deleted etc.)
- defined rules regarding from which state to which a user can go based on different system events
- a rather messy (but mostly working) system full of IFs and SWITCHes scattered all across the place
Want to:
- replace the current IFfy user state handling with a "clever" state machine that would allow to define those user transition rules
- allow to visualise those defined rules
- make the system more secure and bullet proof by making sure the user can only be in legal states
My research:
I checked both SO and other places for a PHP implementation of workflow and state machines and promising candidates seem to be
- The PEAR FSM http://www.indelible.org/php/FSM/guide.html
- or the eZ componenet Workflow http://ezcomponents.org/docs/api/trunk/introduction_Workflow.html
I'd be grateful for any comments regarding any experience with working with either of the libraries above and / or opinion regarding suitability for what I need or for hints to other places where to look to.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的状态设置方式,听起来您可以只设置一个带有工厂的类系统来优雅地处理所有这些?
您还可以使用状态检查来设置类,这可能会引发异常,并且基本上无法实例化该类(因此无法进入该状态)。
我想这样的东西可能对你有用:
显然,这缺少了很多东西,需要做很多事情才能使它成为你可以实际使用的东西,但如果你像这样把东西分开,它就不会很混乱,您将能够知道正在检查每个状态的位置以及正在检查的内容。
Depending on how your states are setup, sounds like you could just setup a class system with a factory to handle all of this elegantly?
You could also setup your classes with state checking, which you could throw exceptions and basically make it impossible to instantiate the class (and therefore impossible to enter that state).
I'm thinking something like this might work for you:
Obviously a lot is missing from this and a lot needs to be done to make this into something you can actually work with, but if you split things up like this, it will not be as messy and you'll be able to know where each state is being checked and what is being checked for.