It's based on the AbstractFactory pattern.
To fully use polymorphism for all your statemachines, you should instantiate
all your machines via factories.
Full polymorphism allows you to build tooling that is the same for every
statemachine you use in your program. The only thing you would need to do is
instantiate the different factories to produce the different machines.
The different sql backends provided store a fully qualified factory class
name for a machine so you can instantiate factories dynamically.
implement the abstract methods in a factory subclass specific to your problem
domain.
$factory = new MySpecificFactory($dependencies_injected_here);
$machine = $factory->getStateMachine($order->getId());
$factory->add($machine->getInitialState());
$machine->run();
Factory method to get a configured Context with the default Builder
and persistence adapter for a concrete statemachine type.
protected createContext ( Identifier $identifier ) : Context |
$identifier |
Identifier |
|
리턴 |
Context |
|