Sometimes you may want to do some checking before a transition and allow or deny
that transition conditionally. You can do exactly this with State
using poilcies.
To create a policy for your machine, simply extend the OffbeatEngineer\State\Policy class
and pass an instance of your policy class to the Machine
constructor as the third
argument.
Before each transition, the state machine will consult the policy by invoking a method named after the transition. It then proceeds only if that method call returns true. As an example:
Transitions not specified in the policy are allowed by default.
If you prefer a safer policy scheme, override the $denial
property on
your policy class to true
. That way, unspecified transitions are denied
by default unless you explicitly allow them in your policy.
If no policy is specified upon machine instantiation, a policy allows all transitions will be used by default.