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 | 215 | public function __construct( |
|
70 | |||
71 | /** |
||
72 | * @param string|StateInterface $state |
||
73 | */ |
||
74 | public function addInitialState($state) |
||
75 | { |
||
76 | if ($state instanceof StateInterface) { |
||
77 | $state = $state->getName(); |
||
78 | } |
||
79 | |||
80 | $this->initialStates[] = $state; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | 170 | public function getInitialStates() |
|
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | 185 | public function getState() |
|
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | 19 | public function process(StateMachineInterface $stateMachine) |
|
105 | |||
106 | /** |
||
107 | * {@inheritdoc} |
||
108 | */ |
||
109 | 185 | public function getName() |
|
113 | |||
114 | /** |
||
115 | * @return callable|null |
||
116 | */ |
||
117 | 42 | public function getGuard() |
|
121 | |||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | 62 | public function resolveProperties(array $properties) |
|
126 | { |
||
127 | try { |
||
128 | 62 | 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() |
|
166 | { |
||
167 | 10 | $missingOptions = $this->propertiesOptionsResolver->getMissingOptions(); |
|
168 | |||
169 | 10 | if (0 === count($missingOptions)) { |
|
170 | 5 | return $this->propertiesOptionsResolver->resolve(array()); |
|
171 | } |
||
172 | |||
173 | 5 | $options = array_combine($missingOptions, array_fill(0, count($missingOptions), null)); |
|
174 | |||
175 | 5 | return array_diff_key( |
|
176 | 5 | $this->propertiesOptionsResolver->resolve($options), |
|
177 | 5 | array_combine($missingOptions, $missingOptions) |
|
178 | ); |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * @return string |
||
183 | */ |
||
184 | public function __toString() |
||
188 | } |
||
189 |