1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Kdyby (http://www.kdyby.org) |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2008 Filip Procházka ([email protected]) |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the file license.txt that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Kdyby\Doctrine\Console; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\Console\Command\Command; |
14
|
|
|
use Symfony\Component\Console\Input\InputOption; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Command Delegate. |
20
|
|
|
* |
21
|
|
|
* @author Fabio B. Silva <[email protected]> |
22
|
|
|
* @author Filip Procházka <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
abstract class DbalDelegateCommand extends Command |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var \Symfony\Component\Console\Command\Command |
28
|
|
|
*/ |
29
|
|
|
protected $command; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return \Symfony\Component\Console\Command\Command |
33
|
|
|
*/ |
34
|
|
|
abstract protected function createCommand(); |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $connectionName |
38
|
|
|
* @return \Symfony\Component\Console\Command\Command |
39
|
|
|
*/ |
40
|
|
|
protected function wrapCommand($connectionName) |
41
|
|
|
{ |
42
|
|
|
CommandHelper::setApplicationConnection($this->getHelper('container'), $connectionName); |
43
|
|
|
$this->command->setApplication($this->getApplication()); |
44
|
|
|
return $this->command; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritDoc} |
49
|
|
|
*/ |
50
|
|
|
protected function configure() |
51
|
|
|
{ |
52
|
|
|
$this->command = $this->createCommand(); |
53
|
|
|
|
54
|
|
|
$this->setName($this->command->getName()); |
55
|
|
|
$this->setHelp($this->command->getHelp()); |
56
|
|
|
$this->setDefinition($this->command->getDefinition()); |
57
|
|
|
$this->setDescription($this->command->getDescription()); |
58
|
|
|
|
59
|
|
|
$this->addOption('connection', NULL, InputOption::VALUE_OPTIONAL, 'The connection to use for this command'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritDoc} |
64
|
|
|
*/ |
65
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
66
|
|
|
{ |
67
|
|
|
return $this->wrapCommand($input->getOption('connection'))->execute($input, $output); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritDoc} |
72
|
|
|
*/ |
73
|
|
|
protected function interact(InputInterface $input, OutputInterface $output) |
74
|
|
|
{ |
75
|
|
|
$this->wrapCommand($input->getOption('connection'))->interact($input, $output); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritDoc} |
80
|
|
|
*/ |
81
|
|
|
protected function initialize(InputInterface $input, OutputInterface $output) |
82
|
|
|
{ |
83
|
|
|
$this->wrapCommand($input->getOption('connection'))->initialize($input, $output); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|