-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathCommand.php
More file actions
116 lines (105 loc) · 4.2 KB
/
Command.php
File metadata and controls
116 lines (105 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
declare(strict_types=1);
namespace Bow\Console;
use ErrorException;
use Bow\Console\Command\ReplCommand;
use Bow\Console\Command\ClearCommand;
use Bow\Console\Command\SeederCommand;
use Bow\Console\Command\ServerCommand;
use Bow\Console\Command\WorkerCommand;
use Bow\Console\Command\MigrationCommand;
use Bow\Console\Command\Generator\GenerateKeyCommand;
use Bow\Console\Command\Generator\GenerateCacheCommand;
use Bow\Console\Command\Generator\GenerateModelCommand;
use Bow\Console\Command\Generator\GenerateQueueCommand;
use Bow\Console\Command\Generator\GenerateSeederCommand;
use Bow\Console\Command\Generator\GenerateConsoleCommand;
use Bow\Console\Command\Generator\GenerateServiceCommand;
use Bow\Console\Command\Generator\GenerateSessionCommand;
use Bow\Console\Command\Generator\GenerateAppEventCommand;
use Bow\Console\Command\Generator\GenerateWorkerCommand;
use Bow\Console\Command\Generator\GenerateExceptionCommand;
use Bow\Console\Command\Generator\GenerateMessagingCommand;
use Bow\Console\Command\Generator\GenerateMigrationCommand;
use Bow\Console\Command\Generator\GenerateControllerCommand;
use Bow\Console\Command\Generator\GenerateMiddlewareCommand;
use Bow\Console\Command\Generator\GenerateValidationCommand;
use Bow\Console\Command\Generator\GenerateNotificationCommand;
use Bow\Console\Command\Generator\GenerateConfigurationCommand;
use Bow\Console\Command\Generator\GenerateEventListenerCommand;
use Bow\Console\Command\Generator\GenerateRouterResourceCommand;
class Command extends AbstractCommand
{
/**
* List of command actions
*
* @var array
*/
private array $commands = [
"clear" => ClearCommand::class,
"seed:table" => SeederCommand::class,
"seed:all" => SeederCommand::class,
"migration:migrate" => MigrationCommand::class,
"migration:rollback" => MigrationCommand::class,
"migration:reset" => MigrationCommand::class,
"add:controller" => GenerateControllerCommand::class,
"add:configuration" => GenerateConfigurationCommand::class,
"add:exception" => GenerateExceptionCommand::class,
"add:middleware" => GenerateMiddlewareCommand::class,
"add:migration" => GenerateMigrationCommand::class,
"add:model" => GenerateModelCommand::class,
"add:seeder" => GenerateSeederCommand::class,
"add:service" => GenerateServiceCommand::class,
"add:validation" => GenerateValidationCommand::class,
"add:event" => GenerateAppEventCommand::class,
"add:listener" => GenerateEventListenerCommand::class,
"add:producer" => GenerateWorkerCommand::class,
"add:command" => GenerateConsoleCommand::class,
"add:message" => GenerateMessagingCommand::class,
"run:console" => ReplCommand::class,
"run:server" => ServerCommand::class,
"run:worker" => WorkerCommand::class,
"flush:worker" => WorkerCommand::class,
"generate:key" => GenerateKeyCommand::class,
"generate:resource" => GenerateRouterResourceCommand::class,
"generate:session-table" => GenerateSessionCommand::class,
"generate:queue-table" => GenerateQueueCommand::class,
"generate:cache-table" => GenerateCacheCommand::class,
"generate:notification-table" => GenerateNotificationCommand::class,
];
/**
* Get the commands
*
* @return array
*/
public function getCommands(): array
{
return $this->commands;
}
/**
* The call command
*
* @param string $action
* @param string $command
* @param array $rest
* @return mixed
* @throws ErrorException
*/
public function call(string $command, string $action, ...$rest): mixed
{
$class = $this->commands[$command] ?? null;
if (is_null($class)) {
$this->throwFailsCommand("The command $command not found !");
}
if (!preg_match('/^(migration)/', $command)) {
$method = "run";
} else {
$method = $action;
}
$instance = new $class($this->setting, $this->arg);
if (method_exists($instance, $method)) {
return call_user_func_array([$instance, $method], $rest);
}
return null;
}
}