Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame^] | 1 | <?php |
| 2 | |
| 3 | namespace Carbon\Cli; |
| 4 | |
| 5 | class Invoker |
| 6 | { |
| 7 | public const CLI_CLASS_NAME = 'Carbon\\Cli'; |
| 8 | |
| 9 | protected function runWithCli(string $className, array $parameters): bool |
| 10 | { |
| 11 | $cli = new $className(); |
| 12 | |
| 13 | return $cli(...$parameters); |
| 14 | } |
| 15 | |
| 16 | public function __invoke(...$parameters): bool |
| 17 | { |
| 18 | if (class_exists(self::CLI_CLASS_NAME)) { |
| 19 | return $this->runWithCli(self::CLI_CLASS_NAME, $parameters); |
| 20 | } |
| 21 | |
| 22 | $function = (($parameters[1] ?? '') === 'install' ? ($parameters[2] ?? null) : null) ?: 'shell_exec'; |
| 23 | $function('composer require carbon-cli/carbon-cli --no-interaction'); |
| 24 | |
| 25 | echo 'Installation succeeded.'; |
| 26 | |
| 27 | return true; |
| 28 | } |
| 29 | } |