1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\Aranguent\Providers; |
6
|
|
|
|
7
|
|
|
use LaravelFreelancerNL\Aranguent\Console\DbCommand; |
8
|
|
|
use Illuminate\Database\Console\DbCommand as IlluminateDbCommand; |
9
|
|
|
use LaravelFreelancerNL\Aranguent\Console\ModelMakeCommand; |
10
|
|
|
use Illuminate\Support\ServiceProvider; |
11
|
|
|
|
12
|
|
|
class CommandServiceProvider extends ServiceProvider |
13
|
|
|
{ |
14
|
|
|
protected bool $defer = false; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The commands to be registered. |
18
|
|
|
* |
19
|
|
|
* @var string[] |
20
|
|
|
*/ |
21
|
|
|
protected $commands = [ |
22
|
|
|
'ModelMake' => ModelMakeCommand::class, |
23
|
|
|
'Db' => DbCommand::class, |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Register the service provider. |
29
|
|
|
* |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
|
|
public function register() |
33
|
|
|
{ |
34
|
|
|
$this->registerCommands($this->commands); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Register the given commands. |
39
|
|
|
* |
40
|
|
|
* @param string[] $commands |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
protected function registerCommands(array $commands) |
44
|
|
|
{ |
45
|
|
|
foreach (array_keys($commands) as $command) { |
46
|
|
|
$this->{"register{$command}Command"}(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$this->commands(array_values($commands)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function registerModelMakeCommand(): void |
53
|
|
|
{ |
54
|
|
|
$this->app->singleton(ModelMakeCommand::class, function ($app) { |
55
|
|
|
return new ModelMakeCommand($app['files']); |
56
|
|
|
}); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function registerDbCommand(): void |
60
|
|
|
{ |
61
|
|
|
$this->app->extend(IlluminateDbCommand::class, function () { |
62
|
|
|
return new DbCommand(); |
63
|
|
|
}); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return string[] |
68
|
|
|
*/ |
69
|
|
|
public function provides() |
70
|
|
|
{ |
71
|
|
|
return array_values($this->commands); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|