1
|
|
|
<?php |
2
|
|
|
/* (c) Anton Medvedev <[email protected]> |
3
|
|
|
* |
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
5
|
|
|
* file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Deployer\Console; |
9
|
|
|
|
10
|
|
|
use Deployer\Component\PharUpdate\Console\Command as PharUpdateCommand; |
11
|
|
|
use Deployer\Component\PharUpdate\Console\Helper as PharUpdateHelper; |
12
|
|
|
use Symfony\Component\Console\Application as Console; |
13
|
|
|
use Symfony\Component\Console\Command\Command; |
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Input\InputOption; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
|
18
|
|
|
class Application extends Console |
19
|
|
|
{ |
20
|
|
|
private $after; |
21
|
|
|
|
22
|
|
|
protected function getDefaultInputDefinition() |
23
|
|
|
{ |
24
|
|
|
$inputDefinition = parent::getDefaultInputDefinition(); |
25
|
|
|
|
26
|
|
|
$inputDefinition->addOption( |
27
|
|
|
new InputOption('--file', '-f', InputOption::VALUE_OPTIONAL, 'Specify Deployer file') |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
return $inputDefinition; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function getDefaultCommands() |
34
|
|
|
{ |
35
|
|
|
$commands = parent::getDefaultCommands(); |
36
|
|
|
|
37
|
|
|
if ($this->isPharArchive()) { |
38
|
|
|
$commands[] = $this->selfUpdateCommand(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return $commands; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function isPharArchive() |
45
|
|
|
{ |
46
|
|
|
return 'phar:' === substr(__FILE__, 0, 5); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
private function selfUpdateCommand() |
50
|
|
|
{ |
51
|
|
|
$selfUpdate = new PharUpdateCommand('self-update'); |
52
|
|
|
$selfUpdate->setDescription('Updates deployer.phar to the latest version'); |
53
|
|
|
$selfUpdate->setManifestUri('https://deployer.org/manifest.json'); |
54
|
|
|
return $selfUpdate; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function getDefaultHelperSet() |
58
|
|
|
{ |
59
|
|
|
$helperSet = parent::getDefaultHelperSet(); |
60
|
|
|
|
61
|
|
|
if ($this->isPharArchive()) { |
62
|
|
|
$helperSet->set(new PharUpdateHelper()); |
63
|
|
|
} |
64
|
|
|
return $helperSet; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output) |
68
|
|
|
{ |
69
|
|
|
$exception = null; |
70
|
|
|
$exitCode = 0; |
71
|
|
|
|
72
|
|
|
try { |
73
|
|
|
$exitCode = parent::doRunCommand($command, $input, $output); |
74
|
|
|
} catch (\Throwable $x) { |
75
|
|
|
$exception = $x; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if (!empty($this->after)) { |
79
|
|
|
call_user_func($this->after, new CommandEvent($command, $input, $output, $exception, $exitCode)); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if ($exception !== null) { |
83
|
|
|
throw $exception; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $exitCode; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function afterRun($callable) |
90
|
|
|
{ |
91
|
|
|
$this->after = $callable; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|