reasonableframework/cli.php

96 lines
2.5 KiB
PHP
Raw Normal View History

2018-07-22 06:12:45 +00:00
#!/bin/php -q
<?php
/**
2018-07-23 05:03:03 +00:00
* @file cli.php
2020-01-28 04:39:54 +00:00
* @created_on 2018-07-22
* @created_on 2020-01-28
2018-07-22 06:12:45 +00:00
* @author Go Namhyeon <gnh1201@gmail.com>
2018-07-23 05:03:03 +00:00
* @brief ReasonableFramework CLI mode
2018-07-22 06:12:45 +00:00
* @cvs http://github.com/gnh1201/reasonableframework
*/
2018-08-24 14:50:12 +00:00
define("_DEF_VSPF_", true); // compatible to VSPF
define("_DEF_RSF_", true); // compatible to RSF
2019-02-19 16:21:19 +00:00
define("APP_DEVELOPMENT", false); // set the status of development
2020-01-28 04:39:54 +00:00
define("DOC_EOL", "\r\n"); // set the 'end of line'
2019-02-19 16:17:46 +00:00
2020-01-28 04:39:54 +00:00
// development mode
2019-02-19 16:17:46 +00:00
if(APP_DEVELOPMENT == true) {
2019-05-20 08:19:05 +00:00
error_reporting(E_ALL);
2020-01-28 04:39:54 +00:00
@ini_set("log_errors", 1);
@ini_set("error_log", sprintf("%s/storage/sandbox/logs/error.log", getcwd()));
} else {
error_reporting(E_ERROR | E_PARSE);
2019-02-19 16:17:46 +00:00
}
2020-01-28 04:39:54 +00:00
@ini_set("display_errors", 1);
2018-07-22 06:12:45 +00:00
2020-01-28 04:39:54 +00:00
// set shared vars
$shared_vars = array();
2019-02-26 02:47:25 +00:00
2018-07-22 06:12:45 +00:00
// define system modules
2020-01-28 04:39:54 +00:00
$load_systems = array("base", "storage", "config", "security", "database", "uri", "logger");
2018-07-22 06:12:45 +00:00
// load system modules
foreach($load_systems as $system_name) {
2019-05-20 08:19:05 +00:00
$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);
}
2020-01-28 04:39:54 +00:00
} else {
echo "ERROR: Dose not exists " . $system_inc_file;
exit;
2019-05-20 08:19:05 +00:00
}
2018-07-22 06:12:45 +00:00
}
2020-01-28 04:39:54 +00:00
// get config
2018-07-22 06:12:45 +00:00
$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);
2018-07-22 08:42:43 +00:00
//@set_time_limit($max_execution_time);
2018-07-22 06:12:45 +00:00
2020-01-28 04:39:54 +00:00
// 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);
}
2018-07-22 06:12:45 +00:00
// autoload module
if(!array_key_empty("enable_autoload", $config)) {
2019-05-20 08:19:05 +00:00
set_autoloader();
2018-07-22 06:12:45 +00:00
}
// set timezone
$default_timezone = get_value_in_array("timezone", $config, "UTC");
date_default_timezone_set($default_timezone);
2020-01-28 04:39:54 +00:00
// set default route
2018-07-22 06:12:45 +00:00
$route = "welcome";
2020-01-28 04:39:54 +00:00
// set arguments of command line
$opts = setopt("r::h::", array("route::", "host::"));
set_shared_var("route", $opts['route']);
set_shared_var("host", $opts['host']);
2018-07-22 06:12:45 +00:00
// load route
if(empty($route)) {
2019-05-20 08:19:05 +00:00
$route = get_value_in_array("default_route", $config, "welcome");
2018-07-22 06:12:45 +00:00
} else {
2019-05-20 08:19:05 +00:00
$route_names = explode('/', $route);
if(count($route_names) > 1) {
$route = $route_names[0];
}
2018-07-22 06:12:45 +00:00
}
// load route file
2020-01-28 04:39:54 +00:00
if(!loadRoute($route, $shared_vars)) {
loadRoute("errors/404", $shared_vars);
2018-07-22 06:12:45 +00:00
}