serviceContainer = $serviceContainer; } /** * $msg will be an instance of `PhpAmqpLib\Message\AMQPMessage` * with the $msg->body being the data sent over RabbitMQ. * * @param AMQPMessage $msg */ public function execute(AMQPMessage $msg) { $msgBody = unserialize($msg->getBody()); if (isset($msgBody['name']) && isset($msgBody['args'])) { // command name and args $name = $msgBody['name']; $args = $msgBody['args']; $input = array(); foreach ($args as $arg) { $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); } } $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; } return false; } }