-
Notifications
You must be signed in to change notification settings - Fork 36
/
cli.php
78 lines (55 loc) · 1.76 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
70
71
72
73
74
75
76
77
78
#!/usr/bin/env php
<?php
use Danack\Console\Application;
use Danack\Console\Output\BufferedOutput;
use ImagickDemo\CLIFunction;
use VarMap\VarMap;
use VarMap\ArrayVarMap;
error_reporting(E_ALL);
require_once __DIR__ . '/vendor/autoload.php';
//require __DIR__ . '/lib/factories.php';
//require __DIR__ . '/lib/exception_mappers_cli.php'
require_once realpath(__DIR__) . '/src/option_functions.php';;
require __DIR__ . "/cli/cli_commands.php";
require __DIR__ . "/src/exception_mappers_cli.php";
set_time_limit(20);
$injector = new Auryn\Injector();
CLIFunction::setupErrorHandlers();
$cliInjectionParams = require __DIR__ . "/src/injectionParams.php";
$cliInjectionParams->addToInjector($injector);
$injector->share($injector);
chdir(realpath(__DIR__) . '/public');
$console = new Application();
add_console_commands($console);
try {
$parsedCommand = $console->parseCommandLine();
}
catch (\Exception $e) {
echo getTextForException($e);
// $output = new BufferedOutput();
// $console->renderException($e, $output);
// echo $output->fetch();
exit(-1);
}
$exceptionMappers = [
Auryn\InjectionException::class => 'cliHandleInjectionException',
];
try {
foreach ($parsedCommand->getParams() as $key => $value) {
$injector->defineParam($key, $value);
}
$variableMap = new ArrayVarMap($parsedCommand->getParams());
$injector->alias(VarMap::class, get_class($variableMap));
$injector->share($variableMap);
$injector->execute($parsedCommand->getCallable());
echo "\n";
}
catch (\Exception $e) {
foreach ($exceptionMappers as $exceptionType => $handler) {
if ($e instanceof $exceptionType) {
$handler($console, $e);
return;
}
}
cliHandleGenericException($console, $e);
}