1 | <?php |
||
13 | class Transition implements TransitionInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var StateInterface |
||
17 | */ |
||
18 | private $targetState; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | private $eventName; |
||
24 | |||
25 | /** |
||
26 | * @var ConditionInterface |
||
27 | */ |
||
28 | private $condition; |
||
29 | |||
30 | /** |
||
31 | * @param StateInterface $targetState |
||
32 | * @param string $eventName |
||
33 | * @param ConditionInterface $condition |
||
34 | */ |
||
35 | 7 | public function __construct(StateInterface $targetState, $eventName = null, ConditionInterface $condition = null) |
|
36 | { |
||
37 | 7 | $this->targetState = $targetState; |
|
38 | 7 | $this->eventName = $eventName; |
|
39 | 7 | $this->condition = $condition; |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * @see MetaborStd\Statemachine.TransitionInterface::getTargetState() |
||
44 | */ |
||
45 | 1 | public function getTargetState() |
|
49 | |||
50 | /** |
||
51 | * @see MetaborStd\Statemachine.TransitionInterface::getEventName() |
||
52 | */ |
||
53 | 3 | public function getEventName() |
|
57 | |||
58 | /** |
||
59 | * @see MetaborStd\Statemachine.TransitionInterface::getConditionName() |
||
60 | */ |
||
61 | 6 | public function getConditionName() |
|
62 | { |
||
63 | 2 | if ($this->condition) { |
|
64 | return $this->condition->getName(); |
||
65 | } |
||
66 | 6 | } |
|
67 | |||
68 | /** |
||
69 | * @see MetaborStd\Statemachine.TransitionInterface::isActive() |
||
70 | */ |
||
71 | 2 | public function isActive($subject, \ArrayAccess $context, EventInterface $event = null) |
|
72 | { |
||
73 | if ($event) { |
||
74 | $result = ($event->getName() == $this->eventName); |
||
75 | } else { |
||
76 | $result = is_null($this->eventName); |
||
77 | 2 | } |
|
78 | if ($this->condition) { |
||
79 | $result = $result && $this->condition->checkCondition($subject, $context); |
||
80 | } |
||
81 | |||
82 | return $result; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @return \MetaborStd\Statemachine\ConditionInterface |
||
87 | */ |
||
88 | 3 | public function getCondition() |
|
92 | } |
||
93 |