RunDqlDoctrineCommand.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\DoctrineBundle\Command;
  11. use Symfony\Component\Console\Input\InputArgument;
  12. use Symfony\Component\Console\Input\InputOption;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. use Symfony\Component\Console\Output\Output;
  16. use Doctrine\ORM\Tools\Console\Command\RunDqlCommand;
  17. /**
  18. * Execute a Doctrine DQL query and output the results.
  19. *
  20. * @author Fabien Potencier <fabien@symfony.com>
  21. * @author Jonathan H. Wage <jonwage@gmail.com>
  22. */
  23. class RunDqlDoctrineCommand extends RunDqlCommand
  24. {
  25. protected function configure()
  26. {
  27. parent::configure();
  28. $this
  29. ->setName('doctrine:query:dql')
  30. ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
  31. ->setHelp(<<<EOT
  32. The <info>doctrine:query:dql</info> command executes the given DQL query and outputs the results:
  33. <info>./app/console doctrine:query:dql "SELECT u FROM UserBundle:User u"</info>
  34. You can also optional specify some additional options like what type of hydration to use when executing the query:
  35. <info>./app/console doctrine:query:dql "SELECT u FROM UserBundle:User u" --hydrate=array</info>
  36. Additionally you can specify the first result and maximum amount of results to show:
  37. <info>./app/console doctrine:query:dql "SELECT u FROM UserBundle:User u" --first-result=0 --max-result=30</info>
  38. EOT
  39. );
  40. }
  41. protected function execute(InputInterface $input, OutputInterface $output)
  42. {
  43. DoctrineCommand::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
  44. return parent::execute($input, $output);
  45. }
  46. }