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.command.make' => Console\DummyCommand::class, |
37
|
|
|
// 'command.handler.command' => Console\DummyCommand::class, |
38
|
|
|
// 'command.handler.event' => Console\DummyCommand::class, |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* The constructor. |
43
|
|
|
* |
44
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
45
|
|
|
*/ |
46
|
4 |
|
public function __construct(Application $app) |
47
|
|
|
{ |
48
|
4 |
|
$this->app = $app; |
49
|
4 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Register generator commands. |
53
|
|
|
*/ |
54
|
4 |
|
public function register() |
55
|
|
|
{ |
56
|
4 |
|
$this->registerCommands(static::$commands); |
57
|
|
|
|
58
|
4 |
|
$this->silentLegacyCommands(static::$legacy_commands); |
59
|
|
|
|
60
|
4 |
|
return array_keys(static::$commands); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Register commands. |
65
|
|
|
* |
66
|
|
|
* @param array $commands |
67
|
|
|
*/ |
68
|
4 |
|
protected function registerCommands(array $commands) |
69
|
|
|
{ |
70
|
4 |
|
foreach ($commands as $name => $class) { |
71
|
4 |
|
if ($this->app->bound($name)) { |
72
|
|
|
$this->app->extend($name, function ($instance, $app) use ($class) { |
73
|
1 |
|
return $app->build($class); |
74
|
1 |
|
}); |
75
|
1 |
|
} |
76
|
|
|
else { |
77
|
|
|
$this->app->singleton($name, function ($app) use ($class) { |
78
|
1 |
|
return $app->build($class); |
79
|
4 |
|
}); |
80
|
|
|
} |
81
|
4 |
|
} |
82
|
4 |
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Setup legacy framework's commands. |
86
|
|
|
* |
87
|
|
|
* @param array $commands |
88
|
|
|
*/ |
89
|
4 |
|
protected function silentLegacyCommands(array $commands) |
90
|
|
|
{ |
91
|
4 |
|
foreach ($commands as $name => $class) { |
92
|
|
|
$this->app->extend($name, function ($instance, $app) use ($class) { |
93
|
|
|
return $app->build($class); |
94
|
|
|
}); |
95
|
4 |
|
} |
96
|
4 |
|
} |
97
|
|
|
} |
98
|
|
|
|