RunDqlDoctrineCommand.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
  3. use Doctrine\ORM\Tools\Console\Command\RunDqlCommand;
  4. use Symfony\Component\Console\Input\InputInterface;
  5. use Symfony\Component\Console\Input\InputOption;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. /**
  8. * Execute a Doctrine DQL query and output the results.
  9. */
  10. class RunDqlDoctrineCommand extends RunDqlCommand
  11. {
  12. /**
  13. * {@inheritDoc}
  14. */
  15. protected function configure()
  16. {
  17. parent::configure();
  18. $this
  19. ->setName('doctrine:query:dql')
  20. ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
  21. ->setHelp(<<<EOT
  22. The <info>%command.name%</info> command executes the given DQL query and
  23. outputs the results:
  24. <info>php %command.full_name% "SELECT u FROM UserBundle:User u"</info>
  25. You can also optional specify some additional options like what type of
  26. hydration to use when executing the query:
  27. <info>php %command.full_name% "SELECT u FROM UserBundle:User u" --hydrate=array</info>
  28. Additionally you can specify the first result and maximum amount of results to
  29. show:
  30. <info>php %command.full_name% "SELECT u FROM UserBundle:User u" --first-result=0 --max-result=30</info>
  31. EOT
  32. );
  33. }
  34. /**
  35. * {@inheritDoc}
  36. */
  37. protected function execute(InputInterface $input, OutputInterface $output)
  38. {
  39. DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
  40. return parent::execute($input, $output);
  41. }
  42. }