1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Paysera\PhpStormHelper\Command; |
6
|
|
|
|
7
|
|
|
use Humbug\SelfUpdate\Updater; |
8
|
|
|
use Phar; |
9
|
|
|
use Symfony\Component\Console\Command\Command; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
13
|
|
|
|
14
|
|
|
class SelfUpdateCommand extends Command |
15
|
|
|
{ |
16
|
|
|
private $updater; |
17
|
|
|
|
18
|
6 |
|
public function __construct(Updater $updater) |
19
|
|
|
{ |
20
|
6 |
|
parent::__construct('self-update'); |
21
|
6 |
|
$this->updater = $updater; |
22
|
6 |
|
} |
23
|
|
|
|
24
|
6 |
|
protected function configure(): void |
25
|
|
|
{ |
26
|
|
|
$this |
27
|
6 |
|
->setDescription(sprintf( |
28
|
6 |
|
'Update %s to most recent stable build.', |
29
|
6 |
|
$this->getLocalPharName() |
30
|
|
|
)) |
31
|
6 |
|
->setAliases(['selfupdate']) |
32
|
|
|
; |
33
|
6 |
|
} |
34
|
|
|
|
35
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
36
|
|
|
{ |
37
|
|
|
$styledOutput = new SymfonyStyle($input, $output); |
38
|
|
|
|
39
|
|
|
$result = $this->updater->update(); |
40
|
|
|
|
41
|
|
|
if ($result) { |
42
|
|
|
$styledOutput->success(sprintf( |
43
|
|
|
'%s has been updated from "%s" to "%s".', |
44
|
|
|
$this->getLocalPharName(), |
45
|
|
|
$this->updater->getOldVersion(), |
46
|
|
|
$this->updater->getNewVersion() |
47
|
|
|
)); |
48
|
|
|
} else { |
49
|
|
|
$styledOutput->success(sprintf('%s is already up to date.', $this->getLocalPharName())); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return 0; |
53
|
|
|
} |
54
|
|
|
|
55
|
6 |
|
private function getLocalPharName(): string |
56
|
|
|
{ |
57
|
6 |
|
return basename(Phar::running()); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|