1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of Laravel Zero. |
7
|
|
|
* |
8
|
|
|
* (c) Nuno Maduro <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace LaravelZero\Framework\Commands\App; |
15
|
|
|
|
16
|
|
|
use LaravelZero\Framework\Components; |
17
|
|
|
use LaravelZero\Framework\Commands\Command; |
18
|
|
|
use PhpSchool\CliMenu\Terminal\TerminalFactory; |
19
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
20
|
|
|
|
21
|
|
|
final class InstallCommand extends Command |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
protected $signature = 'app:install {component? : The component name}'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
protected $description = 'Installs a new component'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The list of components installers. |
35
|
|
|
* |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
private $components = [ |
39
|
|
|
'console-dusk' => Components\ConsoleDusk\Installer::class, |
40
|
|
|
'database' => Components\Database\Installer::class, |
41
|
|
|
'dotenv' => Components\Dotenv\Installer::class, |
42
|
|
|
'log' => Components\Log\Installer::class, |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
7 |
|
public function handle(): void |
49
|
|
|
{ |
50
|
7 |
|
$title = 'Laravel Zero - Component installer'; |
51
|
|
|
|
52
|
|
|
$choices = [ |
53
|
7 |
|
'console-dusk' => 'Console Dusk - Laravel Dusk on artisan commands', |
54
|
|
|
'database' => 'Database - Laravel Eloquent', |
55
|
|
|
'dotenv' => 'Dotenv - Loads environment variables from `.env`', |
56
|
|
|
'log' => 'Log - Laravel Log component', |
57
|
|
|
]; |
58
|
|
|
|
59
|
7 |
|
if (! TerminalFactory::fromSystem() |
60
|
7 |
|
->isTTY()) { |
61
|
|
|
$option = $this->choice($title, $choices); |
62
|
|
|
} else { |
63
|
7 |
|
$option = $this->argument('component') ?: $this->menu( |
|
|
|
|
64
|
|
|
$title, |
65
|
|
|
$choices |
66
|
|
|
) |
67
|
|
|
->setForegroundColour('green') |
68
|
|
|
->setBackgroundColour('black') |
69
|
7 |
|
->open(); |
70
|
|
|
} |
71
|
|
|
|
72
|
7 |
|
if ($option !== null && ! empty($this->components[$option])) { |
73
|
7 |
|
$command = tap($this->app[$this->components[$option]])->setLaravel($this->app); |
74
|
|
|
|
75
|
7 |
|
$this->info("Installing {$option} component..."); |
76
|
|
|
|
77
|
7 |
|
$command->run(new ArrayInput([]), $this->output); |
78
|
|
|
} |
79
|
7 |
|
} |
80
|
|
|
} |
81
|
|
|
|