AMQPRemoteCommand.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace WorkflowBundle\Command;
  3. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  4. use Symfony\Component\Console\Input\InputInterface;
  5. use Symfony\Component\Console\Input\InputOption;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. class AMQPRemoteCommand extends ContainerAwareCommand
  8. {
  9. protected function configure()
  10. {
  11. $this
  12. ->setName('amqp:remote')
  13. ->setDescription('Run a command on an AMQP Consumer')
  14. ->setHelp('Run a command on an AMQP Consumer')
  15. ->addArgument('name', InputOption::VALUE_REQUIRED, 'Command to execute')
  16. ->addOption('args', null, InputOption::VALUE_OPTIONAL|InputOption::VALUE_IS_ARRAY, 'Optional Commands arguments. e.g. --args=key:value --args=key1:value1')
  17. ;
  18. }
  19. /**
  20. * @param InputInterface $input
  21. * @param OutputInterface $output
  22. */
  23. protected function execute(InputInterface $input, OutputInterface $output)
  24. {
  25. $name = $input->getArgument('name');
  26. $args = $input->getOption('args');
  27. if ($name) {
  28. $producer = $this->getContainer()->get('old_sound_rabbit_mq.command_producer_producer');
  29. $producer->publish(serialize(compact('name', 'args')));
  30. $output->writeln('<info>Command executed!</info>');
  31. } else {
  32. $output->writeln('<error>Enter a valid command</error>');
  33. }
  34. }
  35. }