1111
1212namespace Symfony \Component \Workflow \Dumper ;
1313
14+ use Symfony \Component \Workflow \Arc ;
1415use Symfony \Component \Workflow \Definition ;
1516use Symfony \Component \Workflow \Exception \InvalidArgumentException ;
1617use Symfony \Component \Workflow \Marking ;
@@ -69,7 +70,8 @@ public function dump(Definition $definition, ?Marking $marking = null, array $op
6970 $ place ,
7071 $ meta ->getPlaceMetadata ($ place ),
7172 \in_array ($ place , $ definition ->getInitialPlaces (), true ),
72- $ marking ?->has($ place ) ?? false
73+ $ marking ?->has($ place ) ?? false ,
74+ $ marking ?->getTokenCount($ place ) ?? 0
7375 );
7476
7577 $ output [] = $ placeNode ;
@@ -91,16 +93,15 @@ public function dump(Definition $definition, ?Marking $marking = null, array $op
9193 $ transitionLabel = $ transitionMeta ['label ' ];
9294 }
9395
94- foreach ($ transition ->getFroms () as $ from ) {
95- $ from = $ placeNameMap [$ from ];
96-
97- foreach ($ transition ->getTos () as $ to ) {
98- $ to = $ placeNameMap [$ to ];
99-
96+ foreach ($ transition ->getFroms (true ) as $ fromArc ) {
97+ foreach ($ transition ->getTos (true ) as $ toArc ) {
10098 if (self ::TRANSITION_TYPE_STATEMACHINE === $ this ->transitionType ) {
99+ $ from = $ placeNameMap [$ fromArc ->place ];
100+ $ to = $ placeNameMap [$ toArc ->place ];
101+
101102 $ transitionOutput = $ this ->styleStateMachineTransition ($ from , $ to , $ transitionLabel , $ transitionMeta );
102103 } else {
103- $ transitionOutput = $ this ->styleWorkflowTransition ($ from , $ to , $ transitionId , $ transitionLabel , $ transitionMeta );
104+ $ transitionOutput = $ this ->styleWorkflowTransition ($ placeNameMap , $ fromArc , $ toArc , $ transitionId , $ transitionLabel , $ transitionMeta );
104105 }
105106
106107 foreach ($ transitionOutput as $ line ) {
@@ -122,12 +123,15 @@ public function dump(Definition $definition, ?Marking $marking = null, array $op
122123 return implode ("\n" , $ output );
123124 }
124125
125- private function preparePlace (int $ placeId , string $ placeName , array $ meta , bool $ isInitial , bool $ hasMarking ): array
126+ private function preparePlace (int $ placeId , string $ placeName , array $ meta , bool $ isInitial , bool $ hasMarking, int $ tokenCount ): array
126127 {
127128 $ placeLabel = $ placeName ;
128129 if (\array_key_exists ('label ' , $ meta )) {
129130 $ placeLabel = $ meta ['label ' ];
130131 }
132+ if (1 < $ tokenCount ) {
133+ $ placeLabel .= ' ( ' .$ tokenCount .') ' ;
134+ }
131135
132136 $ placeLabel = $ this ->escape ($ placeLabel );
133137
@@ -206,7 +210,7 @@ private function styleStateMachineTransition(string $from, string $to, string $t
206210 return $ transitionOutput ;
207211 }
208212
209- private function styleWorkflowTransition (string $ from , string $ to , int $ transitionId , string $ transitionLabel , array $ transitionMeta ): array
213+ private function styleWorkflowTransition (array $ placeNameMap , Arc $ from , Arc $ to , int $ transitionId , string $ transitionLabel , array $ transitionMeta ): array
210214 {
211215 $ transitionOutput = [];
212216
@@ -220,8 +224,11 @@ private function styleWorkflowTransition(string $from, string $to, int $transiti
220224 $ transitionOutput [] = $ transitionNodeStyle ;
221225 }
222226
223- $ connectionStyle = '%s-->%s ' ;
224- $ transitionOutput [] = \sprintf ($ connectionStyle , $ from , $ transitionNodeName );
227+ if ($ from ->weight > 1 ) {
228+ $ transitionOutput [] = \sprintf ('%s-->|%d|%s ' , $ placeNameMap [$ from ->place ], $ from ->weight , $ transitionNodeName );
229+ } else {
230+ $ transitionOutput [] = \sprintf ('%s-->%s ' , $ placeNameMap [$ from ->place ], $ transitionNodeName );
231+ }
225232
226233 $ linkStyle = $ this ->styleLink ($ transitionMeta );
227234 if ('' !== $ linkStyle ) {
@@ -230,7 +237,11 @@ private function styleWorkflowTransition(string $from, string $to, int $transiti
230237
231238 ++$ this ->linkCount ;
232239
233- $ transitionOutput [] = \sprintf ($ connectionStyle , $ transitionNodeName , $ to );
240+ if ($ to ->weight > 1 ) {
241+ $ transitionOutput [] = \sprintf ('%s-->|%d|%s ' , $ transitionNodeName , $ to ->weight , $ placeNameMap [$ to ->place ]);
242+ } else {
243+ $ transitionOutput [] = \sprintf ('%s-->%s ' , $ transitionNodeName , $ placeNameMap [$ to ->place ]);
244+ }
234245
235246 $ linkStyle = $ this ->styleLink ($ transitionMeta );
236247 if ('' !== $ linkStyle ) {
0 commit comments