-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapplication.php
executable file
·84 lines (71 loc) · 2.11 KB
/
application.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
79
80
81
82
83
84
#!/usr/bin/env php
<?php
use Phalcon\CLI\Console as ConsoleApp,
Phalcon\CLI\Console\Exception;
error_reporting(E_ALL & ~E_DEPRECATED);
define('VERSION', '1.0.0');
getOptions($argv);
$arguments = array();
foreach($argv as $k => $arg) {
if($k == 1) {
$arg = explode(':', $arg);
$arguments['task'] = $arg[0];
if(isset($arg[1])){
$arguments['action'] = $arg[1];
}
} elseif($k >= 2) {
$arguments['params'][] = $arg;
}
}
// Define paths
defined('ROOT_PATH')
|| define('ROOT_PATH', realpath(dirname(__FILE__)));
defined('HOME_PATH')
|| define('HOME_PATH', ROOT_PATH.'/../../..');
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', HOME_PATH.'/apps/'.APP);
defined('TEMPLATE_PATH')
|| define('TEMPLATE_PATH', ROOT_PATH.'/templates');
include __DIR__ . '/config/loader.php';
include __DIR__ . '/config/services.php';
if(!isset($arguments['task'])){
Phalcon\Tools\Cli::error('Task missing');
} else if(!isset($arguments['action'])){
$arguments['action']='main';
}
//Create a console application
$console = new ConsoleApp();
$console->setDI($di);
$di->setShared('console', $console);
// define global constants for the current task and action
define('CURRENT_TASK', (isset($arguments['task']) ? $arguments['task'] : null));
define('CURRENT_ACTION', (isset($arguments['action']) ? $arguments['action'] : null));
try {
// handle incoming arguments
$console->handle($arguments);
}
catch (Exception $e) {
Phalcon\Tools\Cli::error($e->getMessage());
}
function getOptions(&$args){
foreach($args as $index => &$arg){
if(strpos($arg, '--') === 0){
$arg = substr($arg, 2);
$data = explode('=', $arg);
if(count($data)===1){
$data[] = true;
}
define(strtoupper($data[0]),$data[1]);
unset($args[$index]);
}
}
defined('APP')
|| define('APP', 'frontend');
defined('ENV')
|| define('ENV', 'dev');
if(strpos(APP, '/')){
$info = explode('/', APP);
define('APP_NAME', $info[0]);
define('APP_MODULE', $info[1]);
}
}