1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Doctrine Bundle |
5
|
|
|
* |
6
|
|
|
* The code was originally distributed inside the Symfony framework. |
7
|
|
|
* |
8
|
|
|
* (c) Fabien Potencier <[email protected]> |
9
|
|
|
* (c) Doctrine Project, Benjamin Eberlei <[email protected]> |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Saxulum\DoctrineOrmCommands\Command\Proxy; |
16
|
|
|
|
17
|
|
|
use Symfony\Component\Console\Input\InputOption; |
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
20
|
|
|
use Doctrine\ORM\Tools\Console\Command\RunDqlCommand; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Execute a Doctrine DQL query and output the results. |
24
|
|
|
* |
25
|
|
|
* @author Fabien Potencier <[email protected]> |
26
|
|
|
* @author Jonathan H. Wage <[email protected]> |
27
|
|
|
*/ |
28
|
|
View Code Duplication |
class RunDqlDoctrineCommand extends RunDqlCommand |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* {@inheritDoc} |
32
|
|
|
*/ |
33
|
|
|
protected function configure() |
34
|
|
|
{ |
35
|
|
|
parent::configure(); |
36
|
|
|
|
37
|
|
|
$this |
38
|
|
|
->setName('doctrine:query:dql') |
39
|
|
|
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command') |
40
|
|
|
->setHelp(<<<EOT |
41
|
|
|
The <info>doctrine:query:dql</info> command executes the given DQL query and |
42
|
|
|
outputs the results: |
43
|
|
|
|
44
|
|
|
<info>php app/console doctrine:query:dql "SELECT u FROM UserBundle:User u"</info> |
45
|
|
|
|
46
|
|
|
You can also optional specify some additional options like what type of |
47
|
|
|
hydration to use when executing the query: |
48
|
|
|
|
49
|
|
|
<info>php app/console doctrine:query:dql "SELECT u FROM UserBundle:User u" --hydrate=array</info> |
50
|
|
|
|
51
|
|
|
Additionally you can specify the first result and maximum amount of results to |
52
|
|
|
show: |
53
|
|
|
|
54
|
|
|
<info>php app/console doctrine:query:dql "SELECT u FROM UserBundle:User u" --first-result=0 --max-result=30</info> |
55
|
|
|
EOT |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritDoc} |
61
|
|
|
*/ |
62
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
63
|
|
|
{ |
64
|
|
|
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em')); |
65
|
|
|
|
66
|
|
|
return parent::execute($input, $output); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.