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