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
|
|
|
use \Kdyby\StrictObjects\Scream; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var \Symfony\Component\Console\Command\Command |
31
|
|
|
*/ |
32
|
|
|
protected $command; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return \Symfony\Component\Console\Command\Command |
36
|
|
|
*/ |
37
|
|
|
abstract protected function createCommand(); |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string[]|bool|string|null $connectionName |
41
|
|
|
* @return \Symfony\Component\Console\Command\Command |
42
|
|
|
*/ |
43
|
|
|
protected function wrapCommand($connectionName) |
44
|
|
|
{ |
45
|
|
|
CommandHelper::setApplicationConnection($this->getHelper('container'), $connectionName); |
|
|
|
|
46
|
|
|
$this->command->setApplication($this->getApplication()); |
47
|
|
|
return $this->command; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritDoc} |
52
|
|
|
*/ |
53
|
|
|
protected function configure() |
54
|
|
|
{ |
55
|
|
|
$this->command = $this->createCommand(); |
56
|
|
|
|
57
|
|
|
$this->setName($this->command->getName()); |
58
|
|
|
$this->setHelp($this->command->getHelp()); |
59
|
|
|
$this->setDefinition($this->command->getDefinition()); |
60
|
|
|
$this->setDescription($this->command->getDescription()); |
61
|
|
|
|
62
|
|
|
$this->addOption('connection', NULL, InputOption::VALUE_OPTIONAL, 'The connection to use for this command'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritDoc} |
67
|
|
|
*/ |
68
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
69
|
|
|
{ |
70
|
|
|
return $this->wrapCommand($input->getOption('connection'))->execute($input, $output); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritDoc} |
75
|
|
|
*/ |
76
|
|
|
protected function interact(InputInterface $input, OutputInterface $output) |
77
|
|
|
{ |
78
|
|
|
$this->wrapCommand($input->getOption('connection'))->interact($input, $output); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritDoc} |
83
|
|
|
*/ |
84
|
|
|
protected function initialize(InputInterface $input, OutputInterface $output) |
85
|
|
|
{ |
86
|
|
|
$this->wrapCommand($input->getOption('connection'))->initialize($input, $output); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.