Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 1 | <?php |
| 2 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 3 | /** |
| 4 | * This file is part of the Carbon package. |
| 5 | * |
| 6 | * (c) Brian Nesbitt <brian@nesbot.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 12 | namespace Carbon\Cli; |
| 13 | |
| 14 | class Invoker |
| 15 | { |
| 16 | public const CLI_CLASS_NAME = 'Carbon\\Cli'; |
| 17 | |
| 18 | protected function runWithCli(string $className, array $parameters): bool |
| 19 | { |
| 20 | $cli = new $className(); |
| 21 | |
| 22 | return $cli(...$parameters); |
| 23 | } |
| 24 | |
| 25 | public function __invoke(...$parameters): bool |
| 26 | { |
| 27 | if (class_exists(self::CLI_CLASS_NAME)) { |
| 28 | return $this->runWithCli(self::CLI_CLASS_NAME, $parameters); |
| 29 | } |
| 30 | |
| 31 | $function = (($parameters[1] ?? '') === 'install' ? ($parameters[2] ?? null) : null) ?: 'shell_exec'; |
| 32 | $function('composer require carbon-cli/carbon-cli --no-interaction'); |
| 33 | |
| 34 | echo 'Installation succeeded.'; |
| 35 | |
| 36 | return true; |
| 37 | } |
| 38 | } |