/
sora
executable file
·54 lines (44 loc) · 1.3 KB
/
sora
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
#!/usr/bin/env php
<?php
/**
* Sora command line tool.
*
* @author overtrue <i@overtrue.me>
*/
require_once __DIR__.'/vendor/autoload.php';
use App\Services\Console\Application;
define('BASE_PATH', __DIR__);
define('ROOT_PATH', BASE_PATH);
define('APP_PATH', ROOT_PATH . '/app');
define('COMMAND_PATH', APP_PATH . '/commands');
define('STORAGE_PATH', ROOT_PATH . '/storage');
define('APP_START', microtime(true));
require_once ROOT_PATH . '/bootstrap/console/Bootstrap.php';
(new Bootstrap())->init();
$application = new Application();
//Register Commands
function registerCommands($cmdPath, $application, $namespace, $excludedFiles = [])
{
$excludedFiles = (array)$excludedFiles;
foreach (glob($cmdPath) as $file) {
$commandFileName = basename($file);
if (in_array($commandFileName, $excludedFiles)) {
continue;
}
$commandClassName = $namespace . substr($commandFileName, 0, -1 * (strlen('.php')));
$application->add(new $commandClassName);
}
}
$commandFileSuffix = 'Command.php';
registerCommands(
COMMAND_PATH . '/*' . $commandFileSuffix,
$application,
'App\\Commands\\',
$commandFileSuffix
);
registerCommands(
COMMAND_PATH . '/Queue/*' . $commandFileSuffix,
$application,
'App\\Commands\\Queue\\'
);
$application->run();