forked from Minds/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.php
69 lines (58 loc) · 1.79 KB
/
cli.php
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
<?php
$_SCRIPTNAME = basename(__FILE__);
if (PHP_SAPI !== 'cli') {
echo "{$_SCRIPTNAME} this is a CLI script" . PHP_EOL;
exit(1);
}
require_once(dirname(__FILE__) . "/vendor/autoload.php");
error_reporting(E_ALL);
ini_set('display_errors', 1);
date_default_timezone_set('UTC');
array_shift($argv);
if (isset($argv[0]) && $argv[0] == 'help') {
$help = true;
array_shift($argv);
} elseif (array_search('--help', $argv)) {
$help = true;
}
if (!$argv) {
// TODO: list handlers?
echo "{$_SCRIPTNAME}: specify a controller" . PHP_EOL;
exit(1);
}
try {
$minds = new Minds\Core\Minds();
$minds->loadConfigs();
$minds->loadLegacy();
//loading events will instantiate all of the dependencies which won't be configured yet if we're installing
if ($argv[0] !== 'install') {
$minds->loadEvents();
}
$handler = Minds\Cli\Factory::build($argv);
if (!$handler) {
echo "{$_SCRIPTNAME}: controller `{$argv[0]}` not found" . PHP_EOL;
exit(1);
} elseif (!($handler instanceof Minds\Interfaces\CliControllerInterface)) {
echo "{$_SCRIPTNAME}: `{$argv[0]}` is not a controller" . PHP_EOL;
exit(1);
}
if (method_exists($handler, 'setApp')) {
$handler->setApp($minds);
}
if (isset($help)) {
$handler->help($handler->getExecCommand());
} else {
$errorlevel = $handler->{$handler->getExecCommand()}();
echo PHP_EOL;
exit((int) $errorlevel);
}
} catch (Minds\Exceptions\CliException $e) {
echo PHP_EOL . "{$_SCRIPTNAME}: [ERROR] {$e->getMessage()}" . PHP_EOL;
exit(1);
} catch (\Exception $e) {
$exceptionClass = get_class($e);
echo PHP_EOL . "{$_SCRIPTNAME}: [EXCEPTION:{$exceptionClass}] {$e->getMessage()}" . PHP_EOL;
exit(1);
}
echo PHP_EOL;
exit(0);