-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
cli.php
97 lines (80 loc) · 2.53 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/php -q
<?php
/**
* @file cli.php
* @created_on 2018-07-22
* @created_on 2020-04-20
* @author Go Namhyeon <abuse@catswords.net>
* @brief ReasonableFramework CLI mode
* @cvs http://github.com/gnh1201/reasonableframework
*/
// example: php cli.php --route=welcome
define("_DEF_VSPF_", true); // compatible to VSPF
define("_DEF_RSF_", true); // compatible to RSF
define("APP_DEVELOPMENT", false); // set the status of development
define("DOC_EOL", "\r\n"); // set the 'end of line'
// development mode
if(APP_DEVELOPMENT == true) {
error_reporting(E_ALL);
@ini_set("log_errors", 1);
@ini_set("error_log", sprintf("%s/storage/sandbox/logs/error.log", getcwd()));
} else {
error_reporting(E_ERROR | E_PARSE);
}
@ini_set("display_errors", 1);
// set shared vars
$shared_vars = array();
// define system modules
$load_systems = array("base", "storage", "config", "security", "database", "uri", "logger");
// load system modules
foreach($load_systems as $system_name) {
$system_inc_file = "./system/" . $system_name . ".php";
if(file_exists($system_inc_file)) {
if($system_name == "base") {
include($system_inc_file);
register_loaded("system", $system_inc_file);
} else {
loadModule($system_name);
}
} else {
echo "ERROR: Dose not exists " . $system_inc_file;
exit;
}
}
// get config
$config = get_config();
// set max_execution_time
$max_execution_time = get_value_in_array("max_execution_time", $config, 0);
@ini_set("max_execution_time", $max_execution_time);
//@set_time_limit($max_execution_time);
// set memory limit
$memory_limit = get_value_in_array("memory_limit", $config, "");
if(!empty($memory_limit)) {
@ini_set("memory_limit", $memory_limit);
@ini_set("suhosin.memory_limit", $memory_limit);
}
// autoload module
if(!array_key_empty("enable_autoload", $config)) {
set_autoloader();
}
// set timezone
$default_timezone = get_value_in_array("timezone", $config, "UTC");
date_default_timezone_set($default_timezone);
// set default route
$route = "welcome";
// set arguments of command line
$opts = getopt("r::h::", array("route::", "host::"));
if(!empty($opts['route'])) {
$route = $opts['route'];
}
// set global variables
set_shared_var("route", $route);
set_shared_var("host", $opts['host']);
// get PID(Process ID)
set_shared_var("mypid", getmypid());
// set database connection
set_shared_var("dbc", get_db_connect());
// load route file
if(!loadRoute($route, $shared_vars)) {
loadRoute("errors/404", $shared_vars);
}