1717use Symfony \Component \Workflow \Exception \LogicException ;
1818use Symfony \Component \Workflow \MarkingStore \MarkingStoreInterface ;
1919use Symfony \Component \Workflow \MarkingStore \MultipleStateMarkingStore ;
20+ use Symfony \Component \Workflow \Metadata \InMemoryMetadataStore ;
21+ use Symfony \Component \Workflow \Metadata \MetadataStoreInterface ;
2022
2123/**
2224 * @author Fabien Potencier <[email protected] > @@ -29,13 +31,15 @@ class Workflow implements WorkflowInterface
2931 private $ markingStore ;
3032 private $ dispatcher ;
3133 private $ name ;
34+ private $ metadataStore ;
3235
33- public function __construct (Definition $ definition , MarkingStoreInterface $ markingStore = null , EventDispatcherInterface $ dispatcher = null , string $ name = 'unnamed ' )
36+ public function __construct (Definition $ definition , MarkingStoreInterface $ markingStore = null , EventDispatcherInterface $ dispatcher = null , string $ name = 'unnamed ' , MetadataStoreInterface $ metadataStore = null )
3437 {
3538 $ this ->definition = $ definition ;
3639 $ this ->markingStore = $ markingStore ?: new MultipleStateMarkingStore ();
3740 $ this ->dispatcher = $ dispatcher ;
3841 $ this ->name = $ name ;
42+ $ this ->metadataStore = $ metadataStore ?: new InMemoryMetadataStore ();
3943 }
4044
4145 /**
@@ -185,6 +189,14 @@ public function getMarkingStore()
185189 return $ this ->markingStore ;
186190 }
187191
192+ /**
193+ * {@inheritdoc}
194+ */
195+ public function getMetadataStore (): MetadataStoreInterface
196+ {
197+ return $ this ->metadataStore ;
198+ }
199+
188200 private function doCan ($ subject , Marking $ marking , Transition $ transition )
189201 {
190202 foreach ($ transition ->getFroms () as $ place ) {
@@ -213,7 +225,7 @@ private function guardTransition($subject, Marking $marking, Transition $transit
213225 return ;
214226 }
215227
216- $ event = new GuardEvent ($ subject , $ marking , $ transition , $ this -> name );
228+ $ event = new GuardEvent ($ subject , $ marking , $ transition , $ this );
217229
218230 $ this ->dispatcher ->dispatch ('workflow.guard ' , $ event );
219231 $ this ->dispatcher ->dispatch (sprintf ('workflow.%s.guard ' , $ this ->name ), $ event );
@@ -227,7 +239,7 @@ private function leave($subject, Transition $transition, Marking $marking)
227239 $ places = $ transition ->getFroms ();
228240
229241 if (null !== $ this ->dispatcher ) {
230- $ event = new Event ($ subject , $ marking , $ transition , $ this -> name );
242+ $ event = new Event ($ subject , $ marking , $ transition , $ this );
231243
232244 $ this ->dispatcher ->dispatch ('workflow.leave ' , $ event );
233245 $ this ->dispatcher ->dispatch (sprintf ('workflow.%s.leave ' , $ this ->name ), $ event );
@@ -248,7 +260,7 @@ private function transition($subject, Transition $transition, Marking $marking)
248260 return ;
249261 }
250262
251- $ event = new Event ($ subject , $ marking , $ transition , $ this -> name );
263+ $ event = new Event ($ subject , $ marking , $ transition , $ this );
252264
253265 $ this ->dispatcher ->dispatch ('workflow.transition ' , $ event );
254266 $ this ->dispatcher ->dispatch (sprintf ('workflow.%s.transition ' , $ this ->name ), $ event );
@@ -260,7 +272,7 @@ private function enter($subject, Transition $transition, Marking $marking)
260272 $ places = $ transition ->getTos ();
261273
262274 if (null !== $ this ->dispatcher ) {
263- $ event = new Event ($ subject , $ marking , $ transition , $ this -> name );
275+ $ event = new Event ($ subject , $ marking , $ transition , $ this );
264276
265277 $ this ->dispatcher ->dispatch ('workflow.enter ' , $ event );
266278 $ this ->dispatcher ->dispatch (sprintf ('workflow.%s.enter ' , $ this ->name ), $ event );
@@ -281,7 +293,7 @@ private function entered($subject, Transition $transition, Marking $marking)
281293 return ;
282294 }
283295
284- $ event = new Event ($ subject , $ marking , $ transition , $ this -> name );
296+ $ event = new Event ($ subject , $ marking , $ transition , $ this );
285297
286298 $ this ->dispatcher ->dispatch ('workflow.entered ' , $ event );
287299 $ this ->dispatcher ->dispatch (sprintf ('workflow.%s.entered ' , $ this ->name ), $ event );
@@ -297,7 +309,7 @@ private function completed($subject, Transition $transition, Marking $marking)
297309 return ;
298310 }
299311
300- $ event = new Event ($ subject , $ marking , $ transition , $ this -> name );
312+ $ event = new Event ($ subject , $ marking , $ transition , $ this );
301313
302314 $ this ->dispatcher ->dispatch ('workflow.completed ' , $ event );
303315 $ this ->dispatcher ->dispatch (sprintf ('workflow.%s.completed ' , $ this ->name ), $ event );
@@ -310,7 +322,7 @@ private function announce($subject, Transition $initialTransition, Marking $mark
310322 return ;
311323 }
312324
313- $ event = new Event ($ subject , $ marking , $ initialTransition , $ this -> name );
325+ $ event = new Event ($ subject , $ marking , $ initialTransition , $ this );
314326
315327 $ this ->dispatcher ->dispatch ('workflow.announce ' , $ event );
316328 $ this ->dispatcher ->dispatch (sprintf ('workflow.%s.announce ' , $ this ->name ), $ event );
0 commit comments