Invoker.php
33 lines
| 1 | <?php |
| 2 | |
| 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 | namespace IAWPSCOPED\Carbon\Cli; |
| 12 | |
| 13 | /** @internal */ |
| 14 | class Invoker |
| 15 | { |
| 16 | public const CLI_CLASS_NAME = 'IAWPSCOPED\\Carbon\\Cli'; |
| 17 | protected function runWithCli(string $className, array $parameters) : bool |
| 18 | { |
| 19 | $cli = new $className(); |
| 20 | return $cli(...$parameters); |
| 21 | } |
| 22 | public function __invoke(...$parameters) : bool |
| 23 | { |
| 24 | if (\class_exists(self::CLI_CLASS_NAME)) { |
| 25 | return $this->runWithCli(self::CLI_CLASS_NAME, $parameters); |
| 26 | } |
| 27 | $function = (($parameters[1] ?? '') === 'install' ? $parameters[2] ?? null : null) ?: 'shell_exec'; |
| 28 | $function('composer require carbon-cli/carbon-cli --no-interaction'); |
| 29 | echo 'Installation succeeded.'; |
| 30 | return \true; |
| 31 | } |
| 32 | } |
| 33 |