|
@@ -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) {
|
|
|
- $pieces = explode(':', $arg);
|
|
|
- if (isset($pieces[0]) && isset($pieces[1])) {
|
|
|
- $input[$pieces[0]] = $pieces[1];
|
|
|
+ $arg = str_replace('\\', '\\\\', $arg);
|
|
|
+ $pos = strpos($arg, ':');
|
|
|
+ $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;
|
|
|
}
|
|
|
|