1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace WorkflowBundle\Command;
- use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Input\InputOption;
- use Symfony\Component\Console\Output\OutputInterface;
- class AMQPRemoteCommand extends ContainerAwareCommand
- {
- protected function configure()
- {
- $this
- ->setName('amqp:remote')
- ->setDescription('Run a command on an AMQP Consumer')
- ->setHelp('Run a command on an AMQP Consumer')
- ->addArgument('name', InputOption::VALUE_REQUIRED, 'Command to execute')
- ->addOption('args', null, InputOption::VALUE_OPTIONAL|InputOption::VALUE_IS_ARRAY, 'Optional Commands arguments. e.g. --args=key:value --args=key1:value1')
- ->addOption('route', null, InputOption::VALUE_OPTIONAL, 'AMQP Route Key', '')
- ;
- }
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- */
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $name = $input->getArgument('name');
- $args = $input->getOption('args');
- $date = date("Y-m-d H:i:s");
- if ($name) {
- $producer = $this->getContainer()->get('old_sound_rabbit_mq.command_producer_producer');
- $route = $input->getOption('route');
- $producer->publish(serialize(compact('name', 'args')), $route);
- $output->writeln("<info>Command executed:</info> {$date} # {$name} # ".implode(" ",$args));
- } else {
- $output->writeln("<error>Enter a valid command:</error> {$date} # {$name} # ".implode(" ",$args));
- }
- }
- }
|