1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Metabor\Statemachine; |
4
|
|
|
|
5
|
|
|
use Metabor\NamedCollection; |
6
|
|
|
use Metabor\Statemachine\Util\StateCollectionMerger; |
7
|
|
|
use MetaborStd\MergeableInterface; |
8
|
|
|
use MetaborStd\Statemachine\StateCollectionInterface; |
9
|
|
|
use MetaborStd\Statemachine\StateInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Oliver Tischlinger |
13
|
|
|
*/ |
14
|
|
|
class StateCollection implements StateCollectionInterface, MergeableInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var NamedCollection |
18
|
|
|
*/ |
19
|
|
|
private $states; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var StateCollectionMerger |
23
|
|
|
*/ |
24
|
|
|
private $stateCollectionMerger; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
*/ |
28
|
25 |
|
public function __construct() |
29
|
|
|
{ |
30
|
25 |
|
$this->states = new NamedCollection(); |
31
|
25 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @see MetaborStd\Statemachine.StateCollectionInterface::getState() |
35
|
|
|
*/ |
36
|
9 |
|
public function getState($name) |
37
|
|
|
{ |
38
|
9 |
|
return $this->states->get($name); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @see MetaborStd\Statemachine.StateCollectionInterface::getStates() |
43
|
|
|
*/ |
44
|
10 |
|
public function getStates() |
45
|
|
|
{ |
46
|
10 |
|
return $this->states->getIterator(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @see MetaborStd\Statemachine.StateCollectionInterface::hasState() |
51
|
|
|
*/ |
52
|
22 |
|
public function hasState($name) |
53
|
|
|
{ |
54
|
22 |
|
return $this->states->has($name); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param StateInterface $state |
59
|
|
|
*/ |
60
|
25 |
|
public function addState(StateInterface $state) |
61
|
|
|
{ |
62
|
25 |
|
$this->states->add($state); |
63
|
25 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return StateCollectionMerger |
67
|
|
|
*/ |
68
|
|
|
public function getStateCollectionMerger() |
69
|
|
|
{ |
70
|
|
|
if (!$this->stateCollectionMerger) { |
71
|
|
|
$this->stateCollectionMerger = new StateCollectionMerger($this); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $this->stateCollectionMerger; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @see \MetaborStd\MergeableInterface::merge() |
79
|
|
|
*/ |
80
|
|
|
public function merge($source) |
81
|
|
|
{ |
82
|
|
|
$merger = $this->getStateCollectionMerger(); |
83
|
|
|
$merger->merge($source); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|