1818use Symfony \Component \Console \Input \InputArgument ;
1919use Symfony \Component \Console \Input \InputInterface ;
2020use Symfony \Component \Console \Input \InputOption ;
21- use Symfony \Component \Console \Output \ConsoleOutputInterface ;
2221use Symfony \Component \Console \Output \OutputInterface ;
2322use Symfony \Component \Console \Style \SymfonyStyle ;
2423use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
@@ -91,18 +90,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9190 {
9291 $ this ->eventDispatcher ->addSubscriber (new StopWorkerOnMessageLimitListener (1 ));
9392
94- $ io = new SymfonyStyle ($ input , $ output instanceof ConsoleOutputInterface ? $ output ->getErrorOutput () : $ output );
95- $ io ->comment ('Quit this command with CONTROL-C. ' );
93+ $ io = new SymfonyStyle ($ input , $ output );
94+ $ errorIo = $ io ->getErrorStyle ();
95+ $ errorIo ->comment ('Quit this command with CONTROL-C. ' );
9696 if (!$ output ->isVeryVerbose ()) {
97- $ io ->comment ('Re-run the command with a -vv option to see logs about consumed messages. ' );
97+ $ errorIo ->comment ('Re-run the command with a -vv option to see logs about consumed messages. ' );
9898 }
9999
100100 $ failureTransportName = $ input ->getOption ('transport ' );
101101 if (self ::DEFAULT_TRANSPORT_OPTION === $ failureTransportName ) {
102- $ this ->printWarningAvailableFailureTransports ($ io , $ this ->getGlobalFailureReceiverName ());
102+ $ this ->printWarningAvailableFailureTransports ($ errorIo , $ this ->getGlobalFailureReceiverName ());
103103 }
104104 if ('' === $ failureTransportName || null === $ failureTransportName ) {
105- $ failureTransportName = $ this ->interactiveChooseFailureTransport ($ io );
105+ $ failureTransportName = $ this ->interactiveChooseFailureTransport ($ errorIo );
106106 }
107107 $ failureTransportName = self ::DEFAULT_TRANSPORT_OPTION === $ failureTransportName ? $ this ->getGlobalFailureReceiverName () : $ failureTransportName ;
108108
@@ -118,12 +118,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
118118 throw new RuntimeException ('Message id must be passed when in non-interactive mode. ' );
119119 }
120120
121- $ this ->runInteractive ($ failureTransportName , $ io , $ shouldForce );
121+ $ this ->runInteractive ($ failureTransportName , $ io , $ errorIo , $ shouldForce );
122122
123123 return 0 ;
124124 }
125125
126- $ this ->retrySpecificIds ($ failureTransportName , $ ids , $ io , $ shouldForce );
126+ $ this ->retrySpecificIds ($ failureTransportName , $ ids , $ io , $ errorIo , $ shouldForce );
127127
128128 if (!$ this ->shouldStop ) {
129129 $ io ->success ('All done! ' );
@@ -151,7 +151,7 @@ public function handleSignal(int $signal, int|false $previousExitCode = 0): int|
151151 return $ this ->forceExit ? 0 : false ;
152152 }
153153
154- private function runInteractive (string $ failureTransportName , SymfonyStyle $ io , bool $ shouldForce ): void
154+ private function runInteractive (string $ failureTransportName , SymfonyStyle $ io , SymfonyStyle $ errorIo , bool $ shouldForce ): void
155155 {
156156 $ receiver = $ this ->failureTransports ->get ($ failureTransportName );
157157 $ count = 0 ;
@@ -178,11 +178,11 @@ private function runInteractive(string $failureTransportName, SymfonyStyle $io,
178178 break ;
179179 }
180180
181- $ this ->retrySpecificEnvelopes ($ envelopes , $ failureTransportName , $ io , $ shouldForce );
181+ $ this ->retrySpecificEnvelopes ($ envelopes , $ failureTransportName , $ io , $ errorIo , $ shouldForce );
182182 }
183183 } else {
184184 // get() and ask messages one-by-one
185- $ count = $ this ->runWorker ($ failureTransportName , $ receiver , $ io , $ shouldForce );
185+ $ count = $ this ->runWorker ($ failureTransportName , $ receiver , $ io , $ errorIo , $ shouldForce );
186186 }
187187
188188 // avoid success message if nothing was processed
@@ -191,22 +191,22 @@ private function runInteractive(string $failureTransportName, SymfonyStyle $io,
191191 }
192192 }
193193
194- private function runWorker (string $ failureTransportName , ReceiverInterface $ receiver , SymfonyStyle $ io , bool $ shouldForce ): int
194+ private function runWorker (string $ failureTransportName , ReceiverInterface $ receiver , SymfonyStyle $ io , SymfonyStyle $ errorIo , bool $ shouldForce ): int
195195 {
196196 $ count = 0 ;
197- $ listener = function (WorkerMessageReceivedEvent $ messageReceivedEvent ) use ($ io , $ receiver , $ shouldForce , &$ count ) {
197+ $ listener = function (WorkerMessageReceivedEvent $ messageReceivedEvent ) use ($ io , $ errorIo , $ receiver , $ shouldForce , &$ count ) {
198198 ++$ count ;
199199 $ envelope = $ messageReceivedEvent ->getEnvelope ();
200200
201- $ this ->displaySingleMessage ($ envelope , $ io );
201+ $ this ->displaySingleMessage ($ envelope , $ io, $ errorIo );
202202
203203 if ($ envelope ->last (MessageDecodingFailedStamp::class)) {
204204 throw new \RuntimeException (\sprintf ('The message with id "%s" could not decoded, it can only be shown or removed. ' , $ this ->getMessageId ($ envelope ) ?? '? ' ));
205205 }
206206
207207 $ this ->forceExit = true ;
208208 try {
209- $ shouldHandle = $ shouldForce || 'retry ' === $ io ->choice ('Please select an action ' , ['retry ' , 'delete ' ], 'retry ' );
209+ $ shouldHandle = $ shouldForce || 'retry ' === $ errorIo ->choice ('Please select an action ' , ['retry ' , 'delete ' ], 'retry ' );
210210 } finally {
211211 $ this ->forceExit = false ;
212212 }
@@ -237,7 +237,7 @@ private function runWorker(string $failureTransportName, ReceiverInterface $rece
237237 return $ count ;
238238 }
239239
240- private function retrySpecificIds (string $ failureTransportName , array $ ids , SymfonyStyle $ io , bool $ shouldForce ): void
240+ private function retrySpecificIds (string $ failureTransportName , array $ ids , SymfonyStyle $ io , SymfonyStyle $ errorIo , bool $ shouldForce ): void
241241 {
242242 $ receiver = $ this ->getReceiver ($ failureTransportName );
243243
@@ -257,21 +257,21 @@ private function retrySpecificIds(string $failureTransportName, array $ids, Symf
257257 }
258258
259259 $ singleReceiver = new SingleMessageReceiver ($ receiver , $ envelope );
260- $ this ->runWorker ($ failureTransportName , $ singleReceiver , $ io , $ shouldForce );
260+ $ this ->runWorker ($ failureTransportName , $ singleReceiver , $ io , $ errorIo , $ shouldForce );
261261
262262 if ($ this ->shouldStop ) {
263263 break ;
264264 }
265265 }
266266 }
267267
268- private function retrySpecificEnvelopes (array $ envelopes , string $ failureTransportName , SymfonyStyle $ io , bool $ shouldForce ): void
268+ private function retrySpecificEnvelopes (array $ envelopes , string $ failureTransportName , SymfonyStyle $ io , SymfonyStyle $ errorIo , bool $ shouldForce ): void
269269 {
270270 $ receiver = $ this ->getReceiver ($ failureTransportName );
271271
272272 foreach ($ envelopes as $ envelope ) {
273273 $ singleReceiver = new SingleMessageReceiver ($ receiver , $ envelope );
274- $ this ->runWorker ($ failureTransportName , $ singleReceiver , $ io , $ shouldForce );
274+ $ this ->runWorker ($ failureTransportName , $ singleReceiver , $ io , $ errorIo , $ shouldForce );
275275
276276 if ($ this ->shouldStop ) {
277277 break ;
0 commit comments