|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright 2018 Vladimir Jimenez |
|
5
|
|
|
* @license https://github.com/stakx-io/stakx/blob/master/LICENSE.md MIT |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace allejo\stakx\Console; |
|
9
|
|
|
|
|
10
|
|
|
use allejo\stakx\Console\Command\BuildCommand; |
|
11
|
|
|
use Symfony\Component\Console\Application as BaseApplication; |
|
12
|
|
|
use Symfony\Component\Console\Input\ArgvInput; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\Container; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The base application class for stakx. |
|
19
|
|
|
*/ |
|
20
|
|
|
class Application extends BaseApplication |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var bool */ |
|
23
|
|
|
private $safeMode; |
|
24
|
|
|
/** @var bool */ |
|
25
|
|
|
private $useCache; |
|
26
|
|
|
/** @var Container */ |
|
27
|
|
|
private $container; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
public function run(InputInterface $input = null, OutputInterface $output = null) |
|
33
|
|
|
{ |
|
34
|
|
|
$input = new ArgvInput(); |
|
|
|
|
|
|
35
|
|
|
$this->handleApplicationFlags($input); |
|
36
|
|
|
|
|
37
|
|
|
$this->loadContainer([ |
|
38
|
|
|
'parameters' => [ |
|
39
|
|
|
'root_dir' => __DIR__ . '/../', |
|
40
|
|
|
], |
|
41
|
|
|
]); |
|
42
|
|
|
|
|
43
|
|
|
$output = $this->getContainer()->get('output'); |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
if (extension_loaded('xdebug') && !getenv('STAKX_DISABLE_XDEBUG_WARN')) |
|
46
|
|
|
{ |
|
47
|
|
|
$output->writeln('<fg=black;bg=yellow>You are running Stakx with xdebug enabled. This has a major impact on runtime performance.</>'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return parent::run($input, $output); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritdoc} |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function getDefaultCommands() |
|
57
|
|
|
{ |
|
58
|
|
|
$commands = parent::getDefaultCommands(); |
|
59
|
|
|
|
|
60
|
|
|
$commands[] = new BuildCommand(); |
|
61
|
|
|
|
|
62
|
|
|
return $commands; |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/// |
|
66
|
|
|
// Application Settings |
|
67
|
|
|
/// |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get whether or not the application is being run in safe mode. |
|
71
|
|
|
* |
|
72
|
|
|
* @return bool |
|
73
|
|
|
*/ |
|
74
|
|
|
public function inSafeMode() |
|
75
|
|
|
{ |
|
76
|
|
|
return (bool)$this->safeMode; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Set safe mode for the application. |
|
81
|
|
|
* |
|
82
|
|
|
* @param bool $safeMode |
|
83
|
|
|
*/ |
|
84
|
|
|
public function setSafeMode($safeMode) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->safeMode = $safeMode; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Get whether or not to look for and use the application cache. |
|
91
|
|
|
* |
|
92
|
|
|
* @return bool |
|
93
|
|
|
*/ |
|
94
|
|
|
public function useCache() |
|
95
|
|
|
{ |
|
96
|
|
|
return (bool)$this->useCache; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Set whether or not to use an existing cache. |
|
101
|
|
|
* |
|
102
|
|
|
* @param bool $useCache |
|
103
|
|
|
*/ |
|
104
|
|
|
public function setUseCache($useCache) |
|
105
|
|
|
{ |
|
106
|
|
|
$this->useCache = $useCache; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Handle application wide flags. |
|
111
|
|
|
* |
|
112
|
|
|
* @param InputInterface $input |
|
113
|
|
|
*/ |
|
114
|
|
|
private function handleApplicationFlags(InputInterface $input) |
|
115
|
|
|
{ |
|
116
|
|
|
$this->setUseCache($input->hasParameterOption('--use-cache')); |
|
117
|
|
|
$this->setSafeMode($input->hasParameterOption('--safe')); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/// |
|
121
|
|
|
// Container Settings |
|
122
|
|
|
/// |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Get the Service container. |
|
126
|
|
|
* |
|
127
|
|
|
* @return Container |
|
128
|
|
|
*/ |
|
129
|
|
|
public function getContainer() |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->container; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Load the cached application container or build a new one. |
|
136
|
|
|
* |
|
137
|
|
|
* @param array $containerOptions |
|
138
|
|
|
* |
|
139
|
|
|
* @throws \Exception |
|
140
|
|
|
*/ |
|
141
|
|
|
private function loadContainer(array $containerOptions) |
|
142
|
|
|
{ |
|
143
|
|
|
$builder = new ContainerBuilder($containerOptions); |
|
144
|
|
|
|
|
145
|
|
|
require $builder->build(); |
|
146
|
|
|
|
|
147
|
|
|
$this->container = new \ProjectServiceContainer(); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|