Przeglądaj źródła

FD3-223 Se corre el consumer mediante Process

Guillermo Espinoza 7 lat temu
rodzic
commit
f36e657c55
1 zmienionych plików z 16 dodań i 20 usunięć
  1. 16 20
      Services/CommandConsumer.php

+ 16 - 20
Services/CommandConsumer.php

@@ -4,10 +4,8 @@ namespace WorkflowBundle\Services;
 
 use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface;
 use PhpAmqpLib\Message\AMQPMessage;
-use Symfony\Bundle\FrameworkBundle\Console\Application;
 use Symfony\Component\DependencyInjection\ContainerInterface;
-use Symfony\Component\Console\Input\ArrayInput;
-use Symfony\Component\Console\Output\BufferedOutput;
+use Symfony\Component\Process\Process;
 
 class CommandConsumer implements ConsumerInterface
 {
@@ -40,29 +38,27 @@ class CommandConsumer implements ConsumerInterface
             $name = $msgBody['name'];
             $args = $msgBody['args'];
 
-            $kernel = $this->serviceContainer->get('kernel');
-            $application = new Application($kernel);
-            $application->setAutoExit(false);
-
-            $input = array('command' => $name,);
+            $input = array();
             foreach ($args as $arg) {
+                $arg = str_replace('\\', '\\\\', $arg);
                 $pos = strpos($arg, ':');
-                if ($pos) {
-                    $input[substr($arg, 0, $pos)] = substr($arg, $pos + 1);
+                $pos2 = strpos($arg, '--');
+                if ($pos2 === false) {
+                    // command argument, no option
+                    $input[] = substr($arg, $pos + 1);
+                } else {
+                    // reemplazo el primer : por = para las options
+                    $input[] = preg_replace('/:/', '=', $arg, 1);
                 }
             }
             
-            $input = new ArrayInput($input);
-
-            $output = new BufferedOutput();
-
-            $application->run($input, $output);
-
-            // return the output
-            $content = $output->fetch();
-            
+            $consolePath = $this->serviceContainer->get('kernel')->getRootDir() . '/../bin/console';
+            $command = $name . ' ' . implode(' ', $input);
+            $process = new Process("{$consolePath} {$command}");
+            $process->run();
+            $content = $process->getOutput();
             echo $content;
-
+                        
             return true;
         }