1 | <?php |
||
15 | class Process extends Named implements ProcessInterface, MergeableInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var StateCollection |
||
19 | */ |
||
20 | private $states; |
||
21 | |||
22 | /** |
||
23 | * @var StateInterface |
||
24 | */ |
||
25 | private $initialState; |
||
26 | |||
27 | /** |
||
28 | * @var StateCollectionMerger |
||
29 | */ |
||
30 | private $stateCollectionMerger; |
||
31 | |||
32 | /** |
||
33 | * @param string $name |
||
34 | * @param StateInterface $initialState |
||
35 | */ |
||
36 | 12 | public function __construct($name, StateInterface $initialState) |
|
42 | |||
43 | /** |
||
44 | * @param StateInterface $state |
||
45 | */ |
||
46 | 12 | protected function addState(StateInterface $state) |
|
47 | { |
||
48 | 12 | $name = $state->getName(); |
|
49 | 12 | if ($this->states->hasState($name)) { |
|
50 | if ($this->states->getState($name) !== $state) { |
||
51 | throw new \Exception('There is already a different state with name "' . $name . '"'); |
||
52 | } |
||
53 | } else { |
||
54 | 12 | $this->states->addState($state); |
|
55 | /* @var $transition TransitionInterface */ |
||
56 | 12 | foreach ($state->getTransitions() as $transition) { |
|
57 | 5 | $targetState = $transition->getTargetState(); |
|
58 | 5 | $this->addState($targetState); |
|
59 | } |
||
60 | } |
||
61 | 12 | } |
|
62 | |||
63 | /** |
||
64 | */ |
||
65 | 12 | protected function createCollection() |
|
70 | |||
71 | /** |
||
72 | * @see MetaborStd\Statemachine.ProcessInterface::getInitialState() |
||
73 | */ |
||
74 | 9 | public function getInitialState() |
|
78 | |||
79 | /** |
||
80 | * @see MetaborStd\Statemachine.ProcessInterface::getStates() |
||
81 | */ |
||
82 | 1 | public function getStates() |
|
86 | |||
87 | /** |
||
88 | * @param string $name |
||
89 | */ |
||
90 | 2 | public function getState($name) |
|
94 | |||
95 | /** |
||
96 | * @param string $name |
||
97 | * |
||
98 | * @return bool |
||
99 | */ |
||
100 | 1 | public function hasState($name) |
|
104 | |||
105 | /** |
||
106 | * @return StateCollectionMerger |
||
107 | */ |
||
108 | 1 | public function getStateCollectionMerger() |
|
109 | { |
||
110 | 1 | if (!$this->stateCollectionMerger) { |
|
111 | 1 | $this->stateCollectionMerger = new StateCollectionMerger($this->states); |
|
112 | } |
||
113 | |||
114 | 1 | return $this->stateCollectionMerger; |
|
115 | } |
||
116 | |||
117 | /** |
||
118 | * @see \MetaborStd\MergeableInterface::merge() |
||
119 | */ |
||
120 | 1 | public function merge($source) |
|
125 | } |
||
126 |