1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Laravel Zero. |
5
|
|
|
* |
6
|
|
|
* (c) Nuno Maduro <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace LaravelZero\Framework\Commands\App; |
13
|
|
|
|
14
|
|
|
use LaravelZero\Framework\Components; |
15
|
|
|
use LaravelZero\Framework\Commands\Command; |
16
|
|
|
use PhpSchool\CliMenu\Terminal\TerminalFactory; |
17
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* This is the Laravel Zero Framework Installer Command implementation. |
21
|
|
|
*/ |
22
|
|
|
class Installer extends Command |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
protected $signature = 'app:install {component? : The component name}'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
protected $description = 'Installs a new component'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The list of components installers. |
36
|
|
|
* |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
protected $components = [ |
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
|
6 |
|
public function handle(): void |
49
|
|
|
{ |
50
|
6 |
|
$title = 'Laravel Zero - Component installer'; |
51
|
|
|
|
52
|
|
|
$choices = [ |
53
|
6 |
|
'database' => 'Database - Laravel Eloquent', |
54
|
|
|
'log' => 'Log - Laravel Log component', |
55
|
|
|
'dotenv' => 'Dotenv - Loads environment variables from `.env`', |
56
|
|
|
]; |
57
|
|
|
|
58
|
6 |
|
if (! TerminalFactory::fromSystem()->isTTY()) { |
59
|
|
|
$option = $this->choice($title, $choices); |
60
|
|
|
} else { |
61
|
6 |
|
$option = $this->argument('component') ?: $this->menu( |
|
|
|
|
62
|
|
|
$title, |
63
|
|
|
$choices |
64
|
|
|
)->setForegroundColour('green') |
65
|
|
|
->setBackgroundColour('black') |
66
|
6 |
|
->open(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
|
71
|
6 |
|
if ($option !== null && ! empty($this->components[$option])) { |
72
|
6 |
|
($command = $this->app[$this->components[$option]])->setLaravel($this->app); |
73
|
|
|
|
74
|
6 |
|
$this->info("Installing {$option} component..."); |
75
|
|
|
|
76
|
6 |
|
$command->run(new ArrayInput([]), $this->output); |
77
|
|
|
} |
78
|
6 |
|
} |
79
|
|
|
} |
80
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: