-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathCommand.php
More file actions
140 lines (127 loc) · 4.96 KB
/
Copy pathCommand.php
File metadata and controls
140 lines (127 loc) · 4.96 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?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\SchedulerCommand;
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\GenerateExceptionCommand;
use Bow\Console\Command\Generator\GenerateNotifierCommand;
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\GenerateTaskCommand;
use Bow\Console\Command\Generator\GenerateRouterResourceCommand;
use Bow\Console\Exception\ConsoleException;
class Command extends AbstractCommand
{
/**
* List of command actions
*
* @var array
*/
protected static array $commands = [
"clear" => ClearCommand::class,
"seed:file" => 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:task" => GenerateTaskCommand::class,
"add:command" => GenerateConsoleCommand::class,
"add:notifier" => GenerateNotifierCommand::class,
"run:console" => ReplCommand::class,
"run:server" => ServerCommand::class,
"run:worker" => WorkerCommand::class,
"flush:worker" => WorkerCommand::class,
"schedule:run" => SchedulerCommand::class,
"schedule:work" => SchedulerCommand::class,
"schedule:list" => SchedulerCommand::class,
"schedule:next" => SchedulerCommand::class,
"schedule:test" => SchedulerCommand::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 static::$commands;
}
/**
* Push new command
*
* @param array $commands
* @return void
*/
public static function pushCommand(array $commands)
{
foreach ($commands as $key => $command) {
if (isset(static::$commands[$key])) {
throw new ConsoleException("$key command already exists");
}
static::$commands[$key] = $command;
}
}
/**
* 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 = static::$commands[$command] ?? null;
if (is_null($class)) {
$this->throwFailsCommand("The command $command not found !");
}
if (!preg_match('/^(migration|seed|schedule)/', $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;
}
}