1 | <?php |
||
43 | class Application extends \Symfony\Component\Console\Application { |
||
44 | |||
45 | /** @var Container */ |
||
46 | public static $container; |
||
47 | |||
48 | /** @var Container */ |
||
49 | protected $diContainer; |
||
50 | |||
51 | /** @var ConsoleLogger */ |
||
52 | protected $fallbackLogger; |
||
53 | |||
54 | /** @var string */ |
||
55 | protected $endpoint; |
||
56 | |||
57 | /** @var string */ |
||
58 | protected $authToken; |
||
59 | |||
60 | /** @var array */ |
||
61 | protected $allowFailure = [ |
||
62 | 'upgrade:executeCoreUpgradeScripts', |
||
63 | 'upgrade:checkpoint', |
||
64 | 'upgrade:maintenanceMode', |
||
65 | 'help', |
||
66 | 'list' |
||
67 | ]; |
||
68 | |||
69 | /** |
||
70 | * Pass Pimple container into application |
||
71 | * @param Container $container |
||
72 | */ |
||
73 | public function setContainer(Container $container){ |
||
77 | |||
78 | /** |
||
79 | * Get Pimple container |
||
80 | * @return Container |
||
81 | */ |
||
82 | public function getContainer(){ |
||
85 | |||
86 | /** |
||
87 | * @param string $endpoint |
||
88 | */ |
||
89 | public function setEndpoint($endpoint){ |
||
92 | |||
93 | /** |
||
94 | * @return string |
||
95 | */ |
||
96 | public function getEndpoint(){ |
||
99 | |||
100 | /** |
||
101 | * @param $token |
||
102 | */ |
||
103 | public function setAuthToken($token){ |
||
106 | |||
107 | /** |
||
108 | * @return string |
||
109 | */ |
||
110 | public function getAuthToken(){ |
||
113 | |||
114 | /** |
||
115 | * Get logger instance |
||
116 | * @return \Psr\Log\LoggerInterface |
||
117 | */ |
||
118 | public function getLogger(){ |
||
131 | |||
132 | public function initConfig(){ |
||
152 | |||
153 | /** |
||
154 | * Log exception with trace |
||
155 | * @param \Exception $e |
||
156 | */ |
||
157 | public function logException($e){ |
||
162 | |||
163 | /** |
||
164 | * Runs the current application. |
||
165 | * |
||
166 | * @param InputInterface $input An Input instance |
||
167 | * @param OutputInterface $output An Output instance |
||
168 | * @return int 0 if everything went fine, or an error code |
||
169 | * @throws \Exception |
||
170 | */ |
||
171 | public function doRun(InputInterface $input, OutputInterface $output){ |
||
172 | $commandName = $this->getCommandName($input); |
||
173 | try{ |
||
174 | $this->assertOwnCloudFound(); |
||
175 | try{ |
||
176 | $this->initConfig(); |
||
177 | if (!isset($this->diContainer['utils.docLink'])) { |
||
178 | $this->diContainer['utils.docLink'] = function ($c) { |
||
179 | /** @var Locator $locator */ |
||
180 | $locator = $c['utils.locator']; |
||
181 | $installedVersion = implode('.', $locator->getInstalledVersion()); |
||
182 | return new DocLink($installedVersion); |
||
183 | }; |
||
184 | } |
||
185 | } catch (ProcessFailedException $e){ |
||
186 | if (!in_array($commandName, $this->allowFailure)){ |
||
187 | $this->logException($e); |
||
188 | $output->writeln("<error>Initialization failed with message:</error>"); |
||
189 | $output->writeln($e->getProcess()->getOutput()); |
||
190 | $output->writeln('<info>Use upgrade:checkpoint --list to view a list of checkpoints</info>'); |
||
191 | $output->writeln('<info>upgrade:checkpoint --restore [checkpointid] to revert to the last checkpoint</info>'); |
||
192 | $output->writeln('Please attach your update.log to the issues you reporting.'); |
||
193 | return 1; |
||
194 | } |
||
195 | } |
||
196 | // TODO: check if the current command needs a valid OC instance |
||
197 | if (!isset($this->diContainer['logger'])) { |
||
198 | $locator = $this->diContainer['utils.locator']; |
||
199 | $this->initLogger($locator->getDataDir()); |
||
|
|||
200 | } |
||
201 | } catch (\Exception $e){ |
||
202 | if (!in_array($commandName, $this->allowFailure)){ |
||
203 | $this->logException($e); |
||
204 | throw $e; |
||
205 | } |
||
206 | } |
||
207 | return parent::doRun($input, $output); |
||
208 | } |
||
209 | |||
210 | /** |
||
211 | * @param Command $command |
||
212 | * @param InputInterface $input |
||
213 | * @param OutputInterface $output |
||
214 | * @return int |
||
215 | * @throws \Exception |
||
216 | */ |
||
217 | protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output){ |
||
236 | |||
237 | /** |
||
238 | * @param string $baseDir |
||
239 | */ |
||
240 | protected function initLogger($baseDir){ |
||
241 | $container = $this->getContainer(); |
||
242 | $container['logger.output'] = function($c) use ($baseDir) { |
||
243 | $stream = @fopen($baseDir . '/update.log', 'a+'); |
||
244 | if ($stream === false){ |
||
245 | $stream = @fopen('php://stderr', 'a'); |
||
246 | } |
||
247 | return new StreamOutput($stream, StreamOutput::VERBOSITY_DEBUG, false); |
||
248 | }; |
||
249 | $container['logger'] = function($c){ |
||
250 | return new ConsoleLogger($c['logger.output']); |
||
251 | }; |
||
252 | } |
||
253 | |||
254 | /** |
||
255 | * Check for ownCloud instance |
||
256 | * @throws \RuntimeException |
||
257 | */ |
||
258 | public function assertOwnCloudFound(){ |
||
307 | |||
308 | /** |
||
309 | * @param string $path |
||
310 | * @param string $message |
||
311 | */ |
||
312 | protected function assertFileExists($path, $message){ |
||
317 | } |
||
318 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: