big changed: scope -> shared_var

This commit is contained in:
Namhyeon Go 2020-01-28 13:39:54 +09:00
parent e51f00f7bc
commit 03f28612a8
2 changed files with 46 additions and 54 deletions

71
cli.php
View File

@ -2,7 +2,8 @@
<?php <?php
/** /**
* @file cli.php * @file cli.php
* @date 2018-07-22 * @created_on 2018-07-22
* @created_on 2020-01-28
* @author Go Namhyeon <gnh1201@gmail.com> * @author Go Namhyeon <gnh1201@gmail.com>
* @brief ReasonableFramework CLI mode * @brief ReasonableFramework CLI mode
* @cvs http://github.com/gnh1201/reasonableframework * @cvs http://github.com/gnh1201/reasonableframework
@ -11,20 +12,23 @@
define("_DEF_VSPF_", true); // compatible to VSPF define("_DEF_VSPF_", true); // compatible to VSPF
define("_DEF_RSF_", true); // compatible to RSF define("_DEF_RSF_", true); // compatible to RSF
define("APP_DEVELOPMENT", false); // set the status of development define("APP_DEVELOPMENT", false); // set the status of development
define("DOC_EOL", "\r\n"); // set the 'end of line' commonly define("DOC_EOL", "\r\n"); // set the 'end of line'
define("SECURITY_VENDOR", false); // advanced security: set security vendor(company) code
// check if current status is development // development mode
if(APP_DEVELOPMENT == true) { if(APP_DEVELOPMENT == true) {
error_reporting(E_ALL); error_reporting(E_ALL);
ini_set("display_errors", 1); @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 empty scope // set shared vars
$scope = array(); $shared_vars = array();
// define system modules // define system modules
$load_systems = array("base", "storage", "config", "security", "database", "uri"); $load_systems = array("base", "storage", "config", "security", "database", "uri", "logger");
// load system modules // load system modules
foreach($load_systems as $system_name) { foreach($load_systems as $system_name) {
@ -36,10 +40,13 @@ foreach($load_systems as $system_name) {
} else { } else {
loadModule($system_name); loadModule($system_name);
} }
} else {
echo "ERROR: Dose not exists " . $system_inc_file;
exit;
} }
} }
// get configurations // get config
$config = get_config(); $config = get_config();
// set max_execution_time // set max_execution_time
@ -47,6 +54,14 @@ $max_execution_time = get_value_in_array("max_execution_time", $config, 0);
@ini_set("max_execution_time", $max_execution_time); @ini_set("max_execution_time", $max_execution_time);
//@set_time_limit($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 // autoload module
if(!array_key_empty("enable_autoload", $config)) { if(!array_key_empty("enable_autoload", $config)) {
set_autoloader(); set_autoloader();
@ -56,37 +71,13 @@ if(!array_key_empty("enable_autoload", $config)) {
$default_timezone = get_value_in_array("timezone", $config, "UTC"); $default_timezone = get_value_in_array("timezone", $config, "UTC");
date_default_timezone_set($default_timezone); date_default_timezone_set($default_timezone);
// default route // set default route
$route = "welcome"; $route = "welcome";
// parse arguments // set arguments of command line
$num_of_args = count($argv); $opts = setopt("r::h::", array("route::", "host::"));
if($num_of_args > 1) { set_shared_var("route", $opts['route']);
foreach($argv as $k=>$v) { set_shared_var("host", $opts['host']);
switch($v) {
case "--route":
if($k < ($num_of_args - 1)) {
$route = $argv[$k + 1];
} else {
set_error("invaild argument");
show_errors();
}
break;
case "--static-ip":
if($k < ($num_of_args - 1)) {
$host = $argv[$k + 1];
set_scope("static_ip", $host);
} else {
set_error("invaild argument");
show_errors();
}
break;
}
}
} else {
set_error("not enough arguments");
show_errors();
}
// load route // load route
if(empty($route)) { if(empty($route)) {
@ -99,6 +90,6 @@ if(empty($route)) {
} }
// load route file // load route file
if(!loadRoute($route, $scope)) { if(!loadRoute($route, $shared_vars)) {
loadRoute("errors/404", $scope); loadRoute("errors/404", $shared_vars);
} }

View File

@ -12,11 +12,11 @@
define("_DEF_VSPF_", true); // compatible to VSPF define("_DEF_VSPF_", true); // compatible to VSPF
define("_DEF_RSF_", true); // compatible to RSF define("_DEF_RSF_", true); // compatible to RSF
define("APP_DEVELOPMENT", false); // set the status of development define("APP_DEVELOPMENT", false); // set the status of development
define("DOC_EOL", "\r\n"); // set the 'end of line' commonly define("DOC_EOL", "\r\n"); // set the 'end of line'
define("CORS_DOMAINS", false); // common security: allow origin domains (e.g. example.org,*.example.org) define("CORS_DOMAINS", false); // common security: allow origin domains (e.g. example.org,*.example.org)
define("PHP_FIREWALL_REQUEST_URI", strip_tags($_SERVER['REQUEST_URI'])); // with advanced security define("PHP_FIREWALL_REQUEST_URI", strip_tags($_SERVER['REQUEST_URI'])); // advanced security
define("PHP_FIREWALL_ACTIVATION", false); // with advanced security define("PHP_FIREWALL_ACTIVATION", false); // advanced security
define("PHP_DDOS_PROTECTION", false); // with advanced security define("PHP_DDOS_PROTECTION", false); // advanced security
// development mode // development mode
if(APP_DEVELOPMENT == true) { if(APP_DEVELOPMENT == true) {
@ -60,8 +60,8 @@ if(CORS_DOMAINS !== false) {
} }
} }
// set empty scope // set shared vars
$scope = array(); $shared_vars = array();
// define system modules // define system modules
$load_systems = array("base", "storage", "config", "security", "database", "uri", "logger"); $load_systems = array("base", "storage", "config", "security", "database", "uri", "logger");
@ -85,13 +85,14 @@ foreach($load_systems as $system_name) {
// get config // get config
$config = get_config(); $config = get_config();
// set scopes (1.6 - Change calling convention for lagacy PHP) // set shared vars (1.6: changed calling convention for lagacy PHP)
set_scope("dbc", get_db_connect()); set_shared_var("dbc", get_db_connect());
set_scope("requests", read_requests()); set_shared_var("requests", read_requests());
// set max_execution_time // set max_execution_time
$max_execution_time = get_value_in_array("max_execution_time", $config, 0); $max_execution_time = get_value_in_array("max_execution_time", $config, 0);
@ini_set("max_execution_time", $max_execution_time); @ini_set("max_execution_time", $max_execution_time);
//@set_time_limit($max_execution_time);
// set memory limit // set memory limit
$memory_limit = get_value_in_array("memory_limit", $config, ""); $memory_limit = get_value_in_array("memory_limit", $config, "");
@ -118,19 +119,19 @@ write_visit_log();
// get requested route // get requested route
$route = read_route(); $route = read_route();
// with advanced security: enable PHP firewall // advanced security: PHP firewall
if(PHP_FIREWALL_ACTIVATION !== false) { if(PHP_FIREWALL_ACTIVATION !== false) {
loadHelper("php-firewall.lnk"); loadHelper("php-firewall.lnk");
} }
// with advanced security: enable DDOS protection // advanced security: DDOS protection
if(PHP_DDOS_PROTECTION !== false) { if(PHP_DDOS_PROTECTION !== false) {
loadHelper("php-ddos.lnk"); loadHelper("php-ddos.lnk");
} }
// load route file // load route
if(!loadRoute($route, $scope)) { if(!loadRoute($route, $shared_vars)) {
loadRoute("errors/404", $scope); loadRoute("errors/404", $shared_vars);
} }
// flush cache // flush cache