forked from phalcon-orphanage/docs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.php
70 lines (47 loc) · 1.11 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
<?php
/**
* Register the autoloader and tell it to register the src/ directory
*/
$loader = new \Phalcon\Loader();
$loader->registerNamespaces(
[
"PhalconDocs" => __DIR__ . "/scripts/src/",
]
);
$loader->register();
// Using the CLI factory default services container
$di = new \Phalcon\Di\FactoryDefault\Cli();
$di->setShared(
"dispatcher",
function () {
$dispatcher = new \Phalcon\Cli\Dispatcher();
$dispatcher->setDefaultNamespace("PhalconDocs\\Task");
return $dispatcher;
}
);
// Create a console application
$console = new \Phalcon\Cli\Console();
$console->setDI($di);
/**
* Process the console arguments
*/
$arguments = [];
foreach ($argv as $k => $arg) {
if ($k == 1) {
$arguments["task"] = $arg;
} elseif ($k == 2) {
$arguments["action"] = $arg;
} elseif ($k >= 3) {
$arguments["params"][] = $arg;
}
}
try {
// Handle incoming arguments
$console->handle($arguments);
} catch (\Exception $exception) {
fwrite(
STDERR,
"ERROR: " . $exception->getMessage() . PHP_EOL
);
exit(1);
}