1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the CLIFramework package. |
5
|
|
|
* |
6
|
|
|
* (c) Arnaud VEBER <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace CLIFramework; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Application as BaseApplication; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
use Symfony\Component\Console\Input\InputOption; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Application. |
22
|
|
|
*/ |
23
|
|
|
class Application extends BaseApplication |
24
|
|
|
{ |
25
|
|
|
const NAME = 'CLIFramework'; |
|
|
|
|
26
|
|
|
const VERSION = '0.0.1-dev'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The kernel. |
30
|
|
|
* |
31
|
|
|
* @var \Symfony\Component\HttpKernel\KernelInterface $kernel |
32
|
|
|
*/ |
33
|
|
|
private $kernel; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The container. |
37
|
|
|
* |
38
|
|
|
* @var \Symfony\Component\DependencyInjection\ContainerInterface $container |
39
|
|
|
*/ |
40
|
|
|
private $container; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Construct the application. |
44
|
|
|
* |
45
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container |
|
|
|
|
46
|
|
|
* |
47
|
|
|
* @return void |
|
|
|
|
48
|
|
|
*/ |
49
|
|
|
public function __construct(Kernel $kernel) |
50
|
|
|
{ |
51
|
|
|
$this->kernel = $kernel; |
|
|
|
|
52
|
|
|
$this->container = $kernel->getContainer(); |
53
|
|
|
|
54
|
|
|
parent::__construct(self::NAME, self::VERSION); |
55
|
|
|
|
56
|
|
|
if ($this->container->has('event_dispatcher')) { |
57
|
|
|
$this->setDispatcher($this->container->get('event_dispatcher')); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this->getDefinition()->addOption( |
61
|
|
|
new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev') |
62
|
|
|
); |
63
|
|
|
$this->getDefinition()->addOption( |
64
|
|
|
new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.') |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get kernel. |
70
|
|
|
* |
71
|
|
|
* @return \Symfony\Component\HttpKernel\KernelInterface |
72
|
|
|
*/ |
73
|
|
|
public function getKernel() |
74
|
|
|
{ |
75
|
|
|
return $this->kernel; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Runs the current application. |
80
|
|
|
* |
81
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
82
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
83
|
|
|
* |
84
|
|
|
* @return int |
85
|
|
|
*/ |
86
|
|
|
public function doRun(InputInterface $input, OutputInterface $output) |
87
|
|
|
{ |
88
|
|
|
$this->registerCommands(); |
89
|
|
|
|
90
|
|
|
return parent::doRun($input, $output); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Register commands into the application |
95
|
|
|
* |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
|
|
protected function registerCommands() |
99
|
|
|
{ |
100
|
|
|
if ($this->container->hasParameter('app.command.ids')) { |
101
|
|
|
foreach ($this->container->getParameter('app.command.ids') as $id) { |
102
|
|
|
$this->add($this->container->get($id)); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.