blob: 4f35d6c618f8f6d79314cedb2cbcebcab54de3c4 [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?php
2
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01003/**
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 Benkard7b2a3a12021-08-16 10:57:25 +020012namespace Carbon\Cli;
13
14class 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}