reasonableframework/cli.php

98 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
2020-04-20 12:28:04 +00:00
* @created_on 2020-04-20
2022-11-25 14:15:20 +00:00
* @author Go Namhyeon <abuse@catswords.net>
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
*/
2020-04-20 12:28:04 +00:00
// example: php cli.php --route=welcome
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
2020-04-20 11:11:46 +00:00
$opts = getopt("r::h::", array("route::", "host::"));
if(!empty($opts['route'])) {
$route = $opts['route'];
2018-07-22 06:12:45 +00:00
}
2020-04-20 11:11:46 +00:00
// set global variables
set_shared_var("route", $route);
set_shared_var("host", $opts['host']);
2020-04-20 11:53:07 +00:00
// get PID(Process ID)
set_shared_var("mypid", getmypid());
// set database connection
set_shared_var("dbc", get_db_connect());
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
}