|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the PPI Framework. |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2011-2016 Paul Dragoonis <[email protected]> |
|
6
|
|
|
* @license http://opensource.org/licenses/mit-license.php MIT |
|
7
|
|
|
* |
|
8
|
|
|
* @link http://www.ppi.io |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace PPI\Framework\Console; |
|
12
|
|
|
|
|
13
|
|
|
use PPI\Framework\AppInterface; |
|
14
|
|
|
use PPI\Framework\Module\AbstractModule; |
|
15
|
|
|
use Symfony\Component\Console\Application as BaseApplication; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Application. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Vítor Brandão <[email protected]> |
|
24
|
|
|
* @author Paul Dragoonis <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class Application extends BaseApplication |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var PPI\Framework\AppInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $app; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param AppInterface $app |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(AppInterface $app) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->app = $app; |
|
|
|
|
|
|
39
|
|
|
parent::__construct('PPI', $app->getVersion() . ' - ' . $app->getEnvironment() . ($app->isDebug() ? '/debug' : '')); |
|
40
|
|
|
|
|
41
|
|
|
$this->getDefinition()->addOption(new InputOption('--shell', '-s', InputOption::VALUE_NONE, 'Launch the shell.')); |
|
42
|
|
|
$this->getDefinition()->addOption(new InputOption('--process-isolation', null, InputOption::VALUE_NONE, 'Launch commands from shell as a separate process.')); |
|
43
|
|
|
$this->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $app->getEnvironment())); |
|
44
|
|
|
$this->getDefinition()->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.')); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Gets the PPI App associated with this Console. |
|
49
|
|
|
* |
|
50
|
|
|
* @return AppInterface An AppInterface instance |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getApp() |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->app; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Gets the PPI App associated with this Console. |
|
59
|
|
|
* |
|
60
|
|
|
* @return AppInterface An AppInterface instance |
|
61
|
|
|
* |
|
62
|
|
|
* @note This method is here to provide compatibility with Symfony's ContainerAwareCommand. |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getKernel() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->app; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Runs the current application. |
|
71
|
|
|
* |
|
72
|
|
|
* @param InputInterface $input An Input instance |
|
73
|
|
|
* @param OutputInterface $output An Output instance |
|
74
|
|
|
* |
|
75
|
|
|
* @return int 0 if everything went fine, or an error code |
|
76
|
|
|
*/ |
|
77
|
|
|
public function doRun(InputInterface $input, OutputInterface $output) |
|
78
|
|
|
{ |
|
79
|
|
|
$this->registerCommands(); |
|
80
|
|
|
if (true === $input->hasParameterOption(array('--shell', '-s'))) { |
|
81
|
|
|
$shell = new Shell($this); |
|
82
|
|
|
$shell->setProcessIsolation($input->hasParameterOption(array('--process-isolation'))); |
|
83
|
|
|
$shell->run(); |
|
84
|
|
|
|
|
85
|
|
|
return 0; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return parent::doRun($input, $output); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
protected function registerCommands() |
|
92
|
|
|
{ |
|
93
|
|
|
$this->app->boot(); |
|
94
|
|
|
|
|
95
|
|
|
$config = $this->app->getConfig(); |
|
96
|
|
|
|
|
97
|
|
|
$commands = array( |
|
98
|
|
|
new Command\AssetsInstallCommand(), |
|
99
|
|
|
new Command\CacheClearCommand(), |
|
100
|
|
|
new Command\ConfigDebugCommand(), |
|
101
|
|
|
new Command\ModuleDebugCommand(), |
|
102
|
|
|
new Command\RouterDebugCommand(), |
|
103
|
|
|
new Command\RouterMatchCommand(), |
|
104
|
|
|
new Command\ServiceManagerDebugCommand(), |
|
105
|
|
|
); |
|
106
|
|
|
if (isset( |
|
107
|
|
|
$config['module_listener_options']['module_paths'][0], |
|
108
|
|
|
$config['framework']['skeleton_module']['path'] |
|
109
|
|
|
)) { |
|
110
|
|
|
$moduleCreateCommand = new Command\ModuleCreateCommand(); |
|
111
|
|
|
$moduleCreateCommand->setSkeletonModuleDir($config['framework']['skeleton_module']['path']); |
|
112
|
|
|
$moduleCreateCommand->setTargetModuleDir($config['module_listener_options']['module_paths'][0]); |
|
113
|
|
|
|
|
114
|
|
|
// Enabled templating engines |
|
115
|
|
|
if (isset($config['framework']['templating']['engines'])) { |
|
116
|
|
|
$moduleCreateCommand->setEnabledTemplatingEngines($config['framework']['templating']['engines']); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$commands[] = $moduleCreateCommand; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$this->addCommands($commands); |
|
123
|
|
|
|
|
124
|
|
|
// Commands found in active Modules |
|
125
|
|
|
foreach ($this->app->getModules() as $module) { |
|
126
|
|
|
if ($module instanceof AbstractModule) { |
|
127
|
|
|
$module->registerCommands($this); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..