fondbot /
framework
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | namespace FondBot\Console; |
||||
| 6 | |||||
| 7 | use FondBot\FondBot; |
||||
| 8 | use FondBot\Foundation\Api; |
||||
| 9 | use Illuminate\Console\Command; |
||||
| 10 | use FondBot\Foundation\Composer; |
||||
| 11 | |||||
| 12 | class InstallDriverCommand extends Command |
||||
| 13 | { |
||||
| 14 | protected $signature = 'fondbot:driver:install |
||||
| 15 | {name : Driver name to be installed}'; |
||||
| 16 | |||||
| 17 | protected $description = 'Install driver'; |
||||
| 18 | |||||
| 19 | private $api; |
||||
| 20 | private $composer; |
||||
| 21 | |||||
| 22 | public function __construct(Api $api, Composer $composer) |
||||
| 23 | { |
||||
| 24 | parent::__construct(); |
||||
| 25 | |||||
| 26 | $this->api = $api; |
||||
| 27 | $this->composer = $composer; |
||||
| 28 | } |
||||
| 29 | |||||
| 30 | public function handle(): void |
||||
| 31 | { |
||||
| 32 | // Check if package is listed in store |
||||
| 33 | $name = $this->argument('name'); |
||||
| 34 | $driver = $this->api->findDriver($this->argument('name')); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 35 | |||||
| 36 | if ($driver === null) { |
||||
| 37 | $this->error('"'.$name.'" is not found in the available drivers list or is not yet supported by current FondBot version ('.FondBot::VERSION.').'); |
||||
|
0 ignored issues
–
show
Are you sure
$name of type null|string|array can be used in concatenation?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 38 | |||||
| 39 | exit(0); |
||||
|
0 ignored issues
–
show
|
|||||
| 40 | } |
||||
| 41 | |||||
| 42 | if ($this->composer->installed($driver['package'])) { |
||||
| 43 | $this->error('Driver is already installed.'); |
||||
| 44 | |||||
| 45 | return; |
||||
| 46 | } |
||||
| 47 | |||||
| 48 | // Install driver |
||||
| 49 | $this->info('Installing driver...'); |
||||
| 50 | |||||
| 51 | $result = $this->composer->install($driver['package'], function ($_, $line) use (&$output) { |
||||
| 52 | $output .= $line; |
||||
| 53 | }); |
||||
| 54 | |||||
| 55 | if ($result !== 0) { |
||||
| 56 | $this->error($output); |
||||
| 57 | exit($result); |
||||
|
0 ignored issues
–
show
|
|||||
| 58 | } |
||||
| 59 | |||||
| 60 | $this->info('Driver installed. ✔'); |
||||
| 61 | } |
||||
| 62 | } |
||||
| 63 |