This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.php
69 lines (51 loc) · 1.56 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
#!/usr/bin/env php
<?php
use Danack\Console\Application;
use Danack\Console\Output\BufferedOutput;
use Example\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 __DIR__ . "/cli/cli_commands.php";
set_time_limit(20);
$injector = new Auryn\Injector();
CLIFunction::setupErrorHandlers();
$cliInjectionParams = require __DIR__ . "/injectionParams/cli.php";
$cliInjectionParams->addToInjector($injector);
$injector->share($injector);
$console = new Application();
add_console_commands($console);
try {
$parsedCommand = $console->parseCommandLine();
}
catch (\Exception $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);
}