我希望在PHP应用程序中实现用户状态/工作流处理。
目前有:
。
想要:
将当前的rules
而使系统更加安全和防弹。
我的研究:
我检查了SO和其他地方,寻找一个PHP实现的工作流和状态机,有希望的候选者似乎是
PEAR http://www.indelible.org/php/FSM/guide.html
组件化工作流http://ezcomponents.org/docs/api/trunk/introduction_Workflow.html
如有任何与上述图书馆合作的经验和/或关于是否适合我所需要的东西或其他地方寻找的提示的意见,我将不胜感激。
发布于 2011-10-04 16:45:33
取决于您的状态是如何设置的,听起来您只需要设置一个带工厂的类系统来优雅地处理所有这些?
您还可以使用状态检查来设置类,这样可以抛出异常,并且基本上不可能实例化类(因此不可能进入该状态)。
我在想像这样的东西可能对你有用:
class StateFactory {
$currentState;
function __construct(){
if(!isset($_SESSION['currentState'])){
$this->currentState = 'StateOne';
}
else{
$this->currentState = $_SESSION['currentState'];
}
$this->currentState = new {$this->currentState}->processState(); // I think something like this will work
}
function __deconstruct(){
$_SESSION['currentState'] = $this->currentState;
}
}
abstract class State{
abstract function processState();
}
class StateOne extends State{
function processState(){
if(<check what is needed for this state>){
<do what you need to do for this state>
return 'StateTwo';
}
else
{
return 'StateWhatever';
}
}
}
class StateTwo extends State{
function processState(){
if(<check what is needed for this state>){
<do what you need to do for this state>
return 'StateThree';
}
else
{
return 'StateWhatever';
}
}
}
class StateThree extends State{
...
}很明显,这其中缺少了很多东西,需要做很多工作才能让它成为你真正可以使用的东西,但是如果你像这样把事情分开,它就不会那么混乱,你就可以知道每个州都在哪里被检查,以及检查的是什么。
https://stackoverflow.com/questions/7650269
复制相似问题