Closed adamaltman closed 9 years ago
Thank you adamaltman.
You are right to point out that it really does not belong there as part of the statemachine package.
the enforcer is there because I included it in the izzum library as part of a larger personal library. I did not want to seperate rules/commands and statemachine packages into different libraries. The Enforcer came along with the code I included in izzum from the rules package.
The rules package is not only used to create 'statemachine' type rules, but also for more business oriented rules. As such, it is used by me inside applications in multiple places, also outside the context of a statemachine.
The enforcer saves me 'if' statements in application code. $rule = new CheckSomethingIsAllowedRule($myCredentialsObject); $command = new ExecuteSomeFancyStuffCommand($myVeryExpensiveSpaceship);
Enforcer::obey($rule, $command); //instead of if($rule->applies()) { $command->execute(); }
That's fine, and makes sense if you are re-using Rules
and Commands
for other purposes too. But, perhaps for others that come across, an additional note in the docblock may be useful.
Adam, I removed the enforcer from the 2.0 version
https://github.com/rolfvreijdenberger/izzum-statemachine/blob/master/src/rules/Enforcer.php
Why is the Enforcer in the rules directory?
And also, why is it in the state machine (it seems to not care about state)?
P.S. Nice library!