RunDqlDoctrineCommand.php 1.9 KB

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