|
4 | 4 |
|
5 | 5 | namespace TypistTech\PhpMatrix\Console; |
6 | 6 |
|
7 | | -use Composer\InstalledVersions; |
8 | | -use Symfony\Component\Console\Application as ConsoleApplication; |
| 7 | +use Symfony\Component\Console\Application as SymfonyConsoleApplication; |
| 8 | +use Symfony\Component\Console\Helper\FormatterHelper; |
9 | 9 |
|
10 | | -class Application |
| 10 | +class Application extends SymfonyConsoleApplication |
11 | 11 | { |
12 | | - private const string NAME = 'php-matrix'; |
| 12 | + private const BANNER = <<<BANNER |
| 13 | + ____ _ _ ____ __ __ _ _ |
| 14 | + | _ \| | | | _ \ | \/ | __ _| |_ _ __(_)_ __ |
| 15 | + | |_) | |_| | |_) | | |\/| |/ _` | __| '__| \ \/ / |
| 16 | + | __/| _ | __/ | | | | (_| | |_| | | |> < |
| 17 | + |_| |_| |_|_| |_| |_|\__,_|\__|_| |_/_/\_\ |
| 18 | + BANNER; |
13 | 19 |
|
14 | | - public static function make(): ConsoleApplication |
| 20 | + public const BUILD_TIMESTAMP = '@datetime@'; |
| 21 | + |
| 22 | + public function getLongVersion(): string |
15 | 23 | { |
16 | | - $app = new ConsoleApplication( |
17 | | - self::NAME, |
18 | | - InstalledVersions::getPrettyVersion('typisttech/php-matrix') ?? 'unknown', |
| 24 | + $longVersion = self::BANNER; |
| 25 | + $longVersion .= PHP_EOL.PHP_EOL; |
| 26 | + |
| 27 | + $app = sprintf( |
| 28 | + '%-15s <info>%s</info> %s', |
| 29 | + $this->getName(), |
| 30 | + $this->getVersion(), |
| 31 | + self::BUILD_TIMESTAMP, |
| 32 | + ); |
| 33 | + $longVersion .= $app; |
| 34 | + |
| 35 | + $githubUrl = sprintf( |
| 36 | + '<href=https://github.com/typisttech/php-matrix/releases/tag/%1$s>https://github.com/typisttech/php-matrix/releases/tag/%1$s</>', |
| 37 | + $this->getVersion(), |
| 38 | + ); |
| 39 | + // https://github.com/box-project/box/blob/b0123f358f2a32488c92e09bf56f16d185e4e3cb/src/Configuration/Configuration.php#L2116 |
| 40 | + if ((bool) preg_match('/^(?<tag>.+)-\d+-g(?<hash>[a-f0-9]{7})$/', $this->getVersion(), $matches)) { |
| 41 | + // Not on a tag. |
| 42 | + $githubUrl = sprintf( |
| 43 | + '<href=https://github.com/typisttech/php-matrix/compare/%1$s...%2$s>https://github.com/typisttech/php-matrix/compare/%1$s...%2$s</>', |
| 44 | + $matches['tag'], |
| 45 | + $matches['hash'], |
| 46 | + ); |
| 47 | + } |
| 48 | + $longVersion .= PHP_EOL.$githubUrl; |
| 49 | + |
| 50 | + $longVersion .= PHP_EOL.PHP_EOL.'<comment>PHP:</>'; |
| 51 | + |
| 52 | + $phpVersion = sprintf( |
| 53 | + '%-15s %s', |
| 54 | + 'Version', |
| 55 | + PHP_VERSION, |
| 56 | + ); |
| 57 | + $longVersion .= PHP_EOL.$phpVersion; |
| 58 | + |
| 59 | + $phpSapi = sprintf( |
| 60 | + '%-15s %s', |
| 61 | + 'SAPI', |
| 62 | + PHP_SAPI, |
| 63 | + ); |
| 64 | + $longVersion .= PHP_EOL.$phpSapi; |
| 65 | + |
| 66 | + $longVersion .= PHP_EOL.PHP_EOL.'<comment>Support Composer SemVer:</>'; |
| 67 | + |
| 68 | + $supportBlock = (new FormatterHelper) |
| 69 | + ->formatBlock( |
| 70 | + [ |
| 71 | + 'If you find this tool useful, please consider supporting its development.', |
| 72 | + 'Every contribution counts, regardless how big or small.', |
| 73 | + 'I am eternally grateful to all sponsors who fund my open source journey.', |
| 74 | + ], |
| 75 | + 'question', |
| 76 | + true, |
| 77 | + ); |
| 78 | + $longVersion .= PHP_EOL.$supportBlock; |
| 79 | + |
| 80 | + $sponsorUrl = sprintf( |
| 81 | + '%1$-15s <href=%2$s>%2$s</>', |
| 82 | + 'GitHub Sponsor', |
| 83 | + 'https://github.com/sponsors/tangrufus', |
19 | 84 | ); |
| 85 | + $longVersion .= PHP_EOL.PHP_EOL.$sponsorUrl; |
| 86 | + |
| 87 | + $longVersion .= PHP_EOL.PHP_EOL.'<comment>Hire Tang Rufus:</>'; |
20 | 88 |
|
21 | | - $app->addCommands([ |
22 | | - new ComposerCommand, |
23 | | - new ConstraintCommand, |
24 | | - ]); |
| 89 | + $hireBlock = (new FormatterHelper) |
| 90 | + ->formatBlock( |
| 91 | + [ |
| 92 | + 'I am looking for my next role, freelance or full-time.', |
| 93 | + 'If you find this tool useful, I can build you more weird stuffs like this.', |
| 94 | + "Let's talk if you are hiring PHP / Ruby / Go developers.", |
| 95 | + ], |
| 96 | + 'error', |
| 97 | + true, |
| 98 | + ); |
| 99 | + $longVersion .= PHP_EOL.$hireBlock; |
| 100 | + |
| 101 | + $sponsorUrl = sprintf( |
| 102 | + '%1$-15s <href=%2$s>%2$s</>', |
| 103 | + 'Contact', |
| 104 | + 'https://typist.tech/contact/', |
| 105 | + ); |
| 106 | + $longVersion .= PHP_EOL.PHP_EOL.$sponsorUrl; |
25 | 107 |
|
26 | | - return $app; |
| 108 | + return $longVersion; |
27 | 109 | } |
28 | 110 | } |
0 commit comments