PHP 클래스 izzum\statemachine\AbstractFactory

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();
파일 보기 프로젝트 열기: rolfvreijdenberger/izzum-statemachine

공개 메소드들

메소드 설명
getStateMachine ( string $id ) : StateMachine Factory method to get a correctly configured statemachine without creating all the default objects in application code.

보호된 메소드들

메소드 설명
createAdapter ( ) : Adapter Returns an implementation of an Adapter class for the persistence layer
createBuilder ( ) : EntityBuilder Get a builder to build your domain objects
createContext ( Identifier $identifier ) : Context Factory method to get a configured Context with the default Builder and persistence adapter for a concrete statemachine type.
createLoader ( ) : izzum\statemachine\loader\Loader Gets the concrete Loader.
createMachine ( Context $context ) : StateMachine create a statemachine
getMachineName ( ) : string get the machine name for the machines that are produced by this factory.

메소드 상세

createAdapter() 추상적인 보호된 메소드

Returns an implementation of an Adapter class for the persistence layer
abstract protected createAdapter ( ) : Adapter
리턴 izzum\statemachine\persistence\Adapter

createBuilder() 추상적인 보호된 메소드

Get a builder to build your domain objects
abstract protected createBuilder ( ) : EntityBuilder
리턴 EntityBuilder

createContext() 보호된 메소드

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

createLoader() 추상적인 보호된 메소드

A simple implementation might use the LoaderArray
abstract protected createLoader ( ) : izzum\statemachine\loader\Loader
리턴 izzum\statemachine\loader\Loader An implementation of a Loader class (might be implemented on the persistence adapter)

createMachine() 보호된 메소드

create a statemachine
protected createMachine ( Context $context ) : StateMachine
$context Context
리턴 StateMachine

getMachineName() 추상적인 보호된 메소드

will be used by the Identifier and Context
abstract protected getMachineName ( ) : string
리턴 string

getStateMachine() 공개 메소드

TRICKY: When using this method it could lead to unoptimized creation of different builders/loaders/persistence objects. For example: a Loader can be reused, a databaseloader will only have to access a database once for a specific machine to get all the transitions. When using this method when inside a loop of some sorts where multiple statemachines for different entities are needed, it would be wise to cache/reuse the different loaders, builders and persistence adapters. php's spl_object_hash() method would be a good way to cache a fully loaded statemachine. Furthermore, once a Loader, ReferenceBuilder and Adapter for persistence have been instantiated, they can be cached in a field of this class since they can safely be reused and shared. Or just change the context on a machine to have access to all the same transitions, builders etc. of the machine.
public getStateMachine ( string $id ) : StateMachine
$id string the entity id for the Identifier
리턴 StateMachine a statemachine ready to go