forked from babeclaire/Cli-queue-phalcon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.php
73 lines (46 loc) · 1.13 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
<?php
use Phalcon\Di\FactoryDefault\Cli as CliDI;
use Phalcon\Cli\Console as ConsoleApp;
use Phalcon\Loader;
// Using the CLI factory default services container
$di = new CliDI();
/**
* Register the autoloader and tell it to register the tasks directory
*/
$loader = new Loader();
$loader->registerDirs(
[
__DIR__ . "/tasks",
require_once __DIR__ . '/vendor/autoload.php',
]
);
$loader->register();
// Load the configuration file (if any)
$configFile = __DIR__ . "/config/config.php";
if (is_readable($configFile)) {
$config = include $configFile;
$di->set("config", $config);
}
// Create a console application
$console = new ConsoleApp();
$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 (\Phalcon\Exception $e) {
echo $e->getMessage();
exit(255);
}