1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelPlus\Extension\Generators; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Foundation\Application; |
6
|
|
|
use LaravelPlus\Extension\Database; |
7
|
|
|
|
8
|
|
|
class GeneratorCommandRegistrar |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var array |
12
|
|
|
*/ |
13
|
|
|
protected static $commands = [ |
14
|
|
|
// make: |
15
|
|
|
'command+.command.make' => Console\CommandMakeCommand::class, |
16
|
|
|
'command+.controller.make' => Console\ControllerMakeCommand::class, |
17
|
|
|
'command+.event.make' => Console\EventMakeCommand::class, |
18
|
|
|
'command+.job.make' => Console\JobMakeCommand::class, |
19
|
|
|
'command+.listener.make' => Console\ListenerMakeCommand::class, |
20
|
|
|
'command+.mail.make' => Console\MailMakeCommand::class, |
21
|
|
|
'command+.middleware.make' => Console\MiddlewareMakeCommand::class, |
22
|
|
|
'command+.migration.make' => Database\Console\MigrationMakeCommand::class, |
23
|
|
|
'command+.model.make' => Console\ModelMakeCommand::class, |
24
|
|
|
'command+.notification.make' => Console\NotificationMakeCommand::class, |
25
|
|
|
'command+.policy.make' => Console\PolicyMakeCommand::class, |
26
|
|
|
'command+.provider.make' => Console\ProviderMakeCommand::class, |
27
|
|
|
'command+.request.make' => Console\RequestMakeCommand::class, |
28
|
|
|
'command+.seeder.make' => Database\Console\SeederMakeCommand::class, |
29
|
|
|
'command+.test.make' => Console\TestMakeCommand::class, |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
protected static $legacy_commands = [ |
36
|
|
|
'command.auth.make' => Console\DummyCommand::class, |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The constructor. |
41
|
|
|
* |
42
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
43
|
|
|
*/ |
44
|
6 |
|
public function __construct(Application $app) |
45
|
|
|
{ |
46
|
6 |
|
$this->app = $app; |
47
|
6 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Register generator commands. |
51
|
|
|
*/ |
52
|
6 |
|
public function register() |
53
|
|
|
{ |
54
|
6 |
|
$this->registerCommands(static::$commands); |
55
|
|
|
|
56
|
6 |
|
$this->silentLegacyCommands(static::$legacy_commands); |
57
|
|
|
|
58
|
6 |
|
return array_keys(static::$commands); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Register commands. |
63
|
|
|
* |
64
|
|
|
* @param array $commands |
65
|
|
|
*/ |
66
|
6 |
|
protected function registerCommands(array $commands) |
67
|
|
|
{ |
68
|
6 |
|
foreach ($commands as $name => $class) { |
69
|
6 |
|
if ($this->app->bound($name)) { |
70
|
|
|
$this->app->extend($name, function ($instance, $app) use ($class) { |
71
|
1 |
|
return $app->build($class); |
72
|
1 |
|
}); |
73
|
1 |
|
} |
74
|
|
|
else { |
75
|
|
|
$this->app->singleton($name, function ($app) use ($class) { |
76
|
1 |
|
return $app->build($class); |
77
|
6 |
|
}); |
78
|
|
|
} |
79
|
6 |
|
} |
80
|
6 |
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Setup legacy framework's commands. |
84
|
|
|
* |
85
|
|
|
* @param array $commands |
86
|
|
|
*/ |
87
|
6 |
|
protected function silentLegacyCommands(array $commands) |
88
|
|
|
{ |
89
|
6 |
|
foreach ($commands as $name => $class) { |
90
|
6 |
|
$this->app->extend($name, function ($instance, $app) use ($class) { |
91
|
1 |
|
return $app->build($class); |
92
|
6 |
|
}); |
93
|
6 |
|
} |
94
|
6 |
|
} |
95
|
|
|
} |
96
|
|
|
|