-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole
More file actions
32 lines (28 loc) · 931 Bytes
/
console
File metadata and controls
32 lines (28 loc) · 931 Bytes
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
<?php
spl_autoload_extensions(".php");
spl_autoload_register(function ($class) {
$namespace = explode('\\', $class);
$file = __DIR__ . '/' . implode('/', $namespace) . '.php';
if (file_exists($file)) {
require_once $file;
}
});
$commands = include "Commands/registry.php";
// argv[1](実際に実行するコマンド)
// (argv[0]はスクリプトの実行に使う名前 console)
// (例:php console migrate)
$inputCommand = $argv[1];
foreach ($commands as $commandClass) {
$alias = $commandClass::getAlias();
if ($inputCommand === $alias) {
if (in_array('--help', $argv)) {
fwrite(STDOUT, $commandClass::getHelp());
exit(0);
} else {
$command = new $commandClass();
$result = $command->execute();
exit($result);
}
}
}
fwrite(STDOUT, "コマンドを実行できませんでした。" . PHP_EOL);