1 | <?php |
||
19 | class Transition implements PropertiesAwareTransitionInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $initialStates; |
||
25 | |||
26 | /* |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $state; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $name; |
||
35 | |||
36 | /** |
||
37 | * @var callable |
||
38 | */ |
||
39 | protected $guard; |
||
40 | |||
41 | /** |
||
42 | * @var OptionsResolver |
||
43 | */ |
||
44 | protected $propertiesOptionsResolver; |
||
45 | |||
46 | /** |
||
47 | * @param string $name |
||
48 | * @param string|array $initialStates |
||
49 | * @param string $state |
||
50 | * @param callable|null $guard |
||
51 | * @param OptionsResolver $propertiesOptionsResolver |
||
52 | */ |
||
53 | 185 | public function __construct( |
|
54 | $name, |
||
55 | $initialStates, |
||
56 | $state, |
||
57 | $guard = null, |
||
58 | OptionsResolver $propertiesOptionsResolver = null |
||
59 | ) { |
||
60 | 185 | if (null !== $guard && !is_callable($guard)) { |
|
61 | throw new \InvalidArgumentException('Invalid callable guard argument passed to Transition::__construct().'); |
||
62 | } |
||
63 | |||
64 | 185 | $this->name = $name; |
|
65 | 185 | $this->state = $state; |
|
66 | 185 | $this->initialStates = (array) $initialStates; |
|
67 | 185 | $this->guard = $guard; |
|
68 | 185 | $this->propertiesOptionsResolver = $propertiesOptionsResolver ?: new OptionsResolver(); |
|
69 | 185 | } |
|
70 | |||
71 | /** |
||
72 | * @param string|StateInterface $state |
||
73 | */ |
||
74 | public function addInitialState($state) |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | 140 | public function getInitialStates() |
|
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | 155 | public function getState() |
|
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | 17 | public function process(StateMachineInterface $stateMachine) |
|
105 | |||
106 | /** |
||
107 | * {@inheritdoc} |
||
108 | */ |
||
109 | 155 | public function getName() |
|
113 | |||
114 | /** |
||
115 | * @return callable|null |
||
116 | */ |
||
117 | 38 | public function getGuard() |
|
121 | |||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | 58 | public function resolveProperties(array $properties) |
|
126 | { |
||
127 | try { |
||
128 | 58 | return $this->propertiesOptionsResolver->resolve($properties); |
|
129 | } catch (MissingOptionsException $e) { |
||
130 | throw new TransitionException( |
||
131 | 'Testing or applying this transition need a parameter. Provide it or set it optional.', |
||
132 | $e->getCode(), |
||
133 | $e |
||
134 | ); |
||
135 | } catch (UndefinedOptionsException $e) { |
||
136 | throw new TransitionException( |
||
137 | 'You provided an unknown property to test() or apply(). Remove it or declare it in your graph.', |
||
138 | $e->getCode(), |
||
139 | $e |
||
140 | ); |
||
141 | } |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * {@inheritDoc} |
||
146 | */ |
||
147 | 10 | public function has($property) |
|
151 | |||
152 | /** |
||
153 | * {@inheritDoc} |
||
154 | */ |
||
155 | 10 | public function get($property, $default = null) |
|
161 | |||
162 | /** |
||
163 | * {@inheritDoc} |
||
164 | */ |
||
165 | 10 | public function getProperties() |
|
180 | |||
181 | /** |
||
182 | * @return string |
||
183 | */ |
||
184 | public function __toString() |
||
188 | } |
||
189 |