-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconsole
88 lines (73 loc) · 1.62 KB
/
console
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
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env php
<?php
/**
* Author: Abel Halo <[email protected]>
*/
use App\Foundation\Application;
use App\Providers\AppServiceProvider;
use App\Providers\ConsoleServiceProvider;
use Phalcon\CLI\Console as ConsoleApp;
use Phalcon\Config;
use Phalcon\Di;
use Phalcon\Di\FactoryDefault\Cli;
/*
* Register the autoloader and
* tell it to register the tasks directory
*/
$loader = require 'bootstrap/autoload.php';
$loader->registerDirs(
[
ROOT.'/app/Console',
]
);
$loader->register();
require APP_PATH.'/console-helpers.php';
/*
* Inject dependencies
*/
$di = new CLI;
Di::setDefault($di);
/** @var Application $app */
$app = require ROOT.'/bootstrap/app.php';
$app->setDi();
$di->get('config')
->merge(new Config(
require CONFIG_PATH.'/console.php'
));
$app->registerServiceProviders([
AppServiceProvider::class,
ConsoleServiceProvider::class,
]);
/*
* Create a console application
*/
$console = new ConsoleApp();
$console->setDI($di);
$di->setShared('console', $console);
/**
* 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;
}
}
/*
* Define global constants for the current task and action
*/
define('CURRENT_TASK', (isset($argv[1]) ? $argv[1] : null));
define('CURRENT_ACTION', (isset($argv[2]) ? $argv[2] : null));
/*
* Handle incoming arguments
*/
try {
$console->handle($arguments);
} catch (\Phalcon\Exception $e) {
echo $e->getMessage();
exit(255);
}