|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy; |
|
4
|
|
|
|
|
5
|
|
|
use RuntimeException; |
|
6
|
|
|
use Symfony\Component\Console\Command\Command; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Command Delegate. |
|
13
|
|
|
*/ |
|
14
|
|
|
abstract class DelegateCommand extends Command |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var Command */ |
|
17
|
|
|
protected $command; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @return Command |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract protected function createCommand(); |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @return string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function getMinimalVersion() |
|
28
|
|
|
{ |
|
29
|
|
|
return '2.3.0-DEV'; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritDoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
public function isEnabled() |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
return $this->isVersionCompatible(); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param string $entityManagerName |
|
42
|
|
|
* |
|
43
|
|
|
* @return Command |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function wrapCommand($entityManagerName) |
|
46
|
|
|
{ |
|
47
|
|
|
if (! $this->isVersionCompatible()) { |
|
|
|
|
|
|
48
|
|
|
throw new RuntimeException(sprintf('"%s" requires doctrine-orm "%s" or newer', $this->getName(), $this->getMinimalVersion())); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $entityManagerName); |
|
|
|
|
|
|
52
|
|
|
$this->command->setApplication($this->getApplication()); |
|
53
|
|
|
|
|
54
|
|
|
return $this->command; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritDoc} |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function configure() |
|
61
|
|
|
{ |
|
62
|
|
|
if ($this->isVersionCompatible()) { |
|
|
|
|
|
|
63
|
|
|
$this->command = $this->createCommand(); |
|
64
|
|
|
|
|
65
|
|
|
$this->setHelp($this->command->getHelp()); |
|
66
|
|
|
$this->setDefinition($this->command->getDefinition()); |
|
67
|
|
|
$this->setDescription($this->command->getDescription()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* {@inheritDoc} |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->wrapCommand($input->getOption('em'))->execute($input, $output); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* {@inheritDoc} |
|
83
|
|
|
*/ |
|
84
|
|
|
protected function interact(InputInterface $input, OutputInterface $output) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->wrapCommand($input->getOption('em'))->interact($input, $output); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* {@inheritDoc} |
|
91
|
|
|
*/ |
|
92
|
|
|
protected function initialize(InputInterface $input, OutputInterface $output) |
|
93
|
|
|
{ |
|
94
|
|
|
$this->wrapCommand($input->getOption('em'))->initialize($input, $output); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.