@@ -17,28 +17,32 @@ final class RunCommandProcessor implements PsrProcessor, CommandSubscriberInterf
1717 */
1818 private $ projectDir ;
1919
20- public function __construct ($ projectDir )
20+ public function __construct (string $ projectDir )
2121 {
2222 $ this ->projectDir = $ projectDir ;
2323 }
2424
25- public function process (PsrMessage $ message , PsrContext $ context )
25+ public function process (PsrMessage $ message , PsrContext $ context ): Result
2626 {
2727 $ command = RunCommand::jsonUnserialize ($ message ->getBody ());
2828
2929 $ phpBin = (new PhpExecutableFinder ())->find ();
3030 $ consoleBin = file_exists ($ this ->projectDir .'/bin/console ' ) ? './bin/console ' : './app/console ' ;
3131
32- $ process = new Process ($ phpBin .' ' .$ consoleBin .' ' .$ command ->getCommandLine (), $ this ->projectDir );
32+ $ process = new Process ($ phpBin .' ' .$ consoleBin .' ' .$ this ->getCommandLine ($ command ), $ this ->projectDir );
3333
3434 $ process ->run ();
3535
36- $ result = new RunCommandResult ($ process ->getExitCode (), $ process ->getOutput (), $ process ->getErrorOutput ());
36+ if ($ message ->getReplyTo ()) {
37+ $ result = new CommandResult ($ process ->getExitCode (), $ process ->getOutput (), $ process ->getErrorOutput ());
3738
38- return Result::reply ($ context ->createMessage (json_encode ($ result )));
39+ return Result::reply ($ context ->createMessage (json_encode ($ result )));
40+ }
41+
42+ return Result::ack ();
3943 }
4044
41- public static function getSubscribedCommand ()
45+ public static function getSubscribedCommand (): array
4246 {
4347 return [
4448 'processorName ' => Commands::RUN_COMMAND ,
@@ -47,4 +51,24 @@ public static function getSubscribedCommand()
4751 'exclusive ' => true ,
4852 ];
4953 }
54+
55+ /**
56+ * @return string
57+ */
58+ private function getCommandLine (RunCommand $ command ): string
59+ {
60+ $ optionsString = '' ;
61+ foreach ($ command ->getOptions () as $ name => $ value ) {
62+ $ optionsString .= " $ name= $ value " ;
63+ }
64+ $ optionsString = trim ($ optionsString );
65+
66+ $ argumentsString = '' ;
67+ foreach ($ command ->getArguments () as $ value ) {
68+ $ argumentsString .= " $ value " ;
69+ }
70+ $ argumentsString = trim ($ argumentsString );
71+
72+ return trim ($ command ->getCommand ().' ' .$ argumentsString .' ' .$ optionsString );
73+ }
5074}
0 commit comments