|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the box project. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Kevin Herrera <[email protected]> |
|
9
|
|
|
* Théo Fidry <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* This source file is subject to the MIT license that is bundled |
|
12
|
|
|
* with this source code in the file LICENSE. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace KevinGH\Box\Console; |
|
16
|
|
|
|
|
17
|
|
|
use Fidry\Console\Application\Application as FidryApplication; |
|
18
|
|
|
use KevinGH\Box\Console\Command\Check\Signature as CheckSignature; |
|
19
|
|
|
use KevinGH\Box\Console\Command\Compile; |
|
20
|
|
|
use KevinGH\Box\Console\Command\Composer\ComposerCheckVersion; |
|
21
|
|
|
use KevinGH\Box\Console\Command\Composer\ComposerVendorDir; |
|
22
|
|
|
use KevinGH\Box\Console\Command\Diff; |
|
23
|
|
|
use KevinGH\Box\Console\Command\Extract; |
|
24
|
|
|
use KevinGH\Box\Console\Command\GenerateDockerFile; |
|
25
|
|
|
use KevinGH\Box\Console\Command\Info; |
|
26
|
|
|
use KevinGH\Box\Console\Command\Info\Signature as InfoSignature; |
|
27
|
|
|
use KevinGH\Box\Console\Command\Namespace_; |
|
28
|
|
|
use KevinGH\Box\Console\Command\Process; |
|
29
|
|
|
use KevinGH\Box\Console\Command\Validate; |
|
30
|
|
|
use KevinGH\Box\Console\Command\Verify; |
|
31
|
|
|
use function KevinGH\Box\get_box_version; |
|
32
|
|
|
use function sprintf; |
|
33
|
|
|
use function trim; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @private |
|
37
|
|
|
*/ |
|
38
|
|
|
final class Application implements FidryApplication |
|
39
|
|
|
{ |
|
40
|
|
|
private readonly string $version; |
|
41
|
|
|
private readonly string $releaseDate; |
|
42
|
|
|
private string $header; |
|
43
|
|
|
|
|
44
|
|
|
public function __construct( |
|
45
|
|
|
private readonly string $name = 'Box', |
|
46
|
|
|
?string $version = null, |
|
47
|
|
|
string $releaseDate = '@release-date@', |
|
48
|
|
|
private readonly bool $autoExit = true, |
|
49
|
|
|
private readonly bool $catchExceptions = true, |
|
50
|
|
|
) { |
|
51
|
|
|
$this->version = $version ?? get_box_version(); |
|
|
|
|
|
|
52
|
|
|
$this->releaseDate = !str_contains($releaseDate, '@') ? $releaseDate : ''; |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function getName(): string |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->name; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getVersion(): string |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->version; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getLongVersion(): string |
|
66
|
|
|
{ |
|
67
|
|
|
return trim( |
|
68
|
|
|
sprintf( |
|
69
|
|
|
'<info>%s</info> version <comment>%s</comment> %s', |
|
70
|
|
|
$this->getName(), |
|
71
|
|
|
$this->getVersion(), |
|
72
|
|
|
$this->releaseDate, |
|
73
|
|
|
), |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getHelp(): string |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->getHeader(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function getHeader(): string |
|
83
|
|
|
{ |
|
84
|
|
|
if (!isset($this->header)) { |
|
85
|
|
|
$this->header = Logo::LOGO_ASCII.$this->getLongVersion(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return $this->header; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function getCommands(): array |
|
92
|
|
|
{ |
|
93
|
|
|
return [ |
|
94
|
|
|
new ComposerCheckVersion(), |
|
95
|
|
|
new ComposerVendorDir(), |
|
96
|
|
|
new Compile($this->getHeader()), |
|
97
|
|
|
new Diff(), |
|
98
|
|
|
new Info(), |
|
99
|
|
|
new Info('info:general'), |
|
100
|
|
|
new InfoSignature(), |
|
101
|
|
|
new CheckSignature(), |
|
102
|
|
|
new Process(), |
|
103
|
|
|
new Extract(), |
|
104
|
|
|
new Validate(), |
|
105
|
|
|
new Verify(), |
|
106
|
|
|
new GenerateDockerFile(), |
|
107
|
|
|
new Namespace_(), |
|
108
|
|
|
]; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function getDefaultCommand(): string |
|
112
|
|
|
{ |
|
113
|
|
|
return 'list'; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function isAutoExitEnabled(): bool |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->autoExit; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function areExceptionsCaught(): bool |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->catchExceptions; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|