reasonableframework/cli.php

101 lines
2.3 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
2018-07-22 06:12:45 +00:00
* @date 2018-07-22
* @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:17:46 +00:00
define("APP_DEVELOPMENT", false); // add development flag
define("DOC_EOL", "\r\n"); // add 'the end of line' of document
// check if current status is development
if(APP_DEVELOPMENT == true) {
error_reporting(E_ALL);
ini_set("display_errors", 1);
}
2018-07-22 06:12:45 +00:00
// define system modules
2018-09-02 16:03:29 +00:00
$load_systems = array("base", "storage", "config", "security", "uri");
2018-07-22 06:12:45 +00:00
// 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);
}
}
}
// get configurations
$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
// autoload module
if(!array_key_empty("enable_autoload", $config)) {
2018-12-29 04:39:14 +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);
// default route
$route = "welcome";
// parse arguments
$num_of_args = count($argv);
if($num_of_args > 1) {
foreach($argv as $k=>$v) {
switch($v) {
case "--route":
if($k < ($num_of_args - 1)) {
$route = $argv[$k + 1];
} else {
set_error("invaild argument");
show_errors();
}
break;
2018-07-22 08:42:43 +00:00
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;
2018-07-22 06:12:45 +00:00
}
}
} else {
set_error("not enough arguments");
show_errors();
}
// load route
if(empty($route)) {
$route = get_value_in_array("default_route", $config, "welcome");
} else {
$route_names = explode('/', $route);
if(count($route_names) > 1) {
$route = $route_names[0];
}
}
// load route file
if(!loadRoute($route, $scope)) {
loadRoute("errors/404", $scope);
}