big changed: scope -> shared_var

This commit is contained in:
Namhyeon Go 2020-01-28 13:36:56 +09:00
parent 4eeff3100a
commit e51f00f7bc
9 changed files with 63 additions and 63 deletions

View File

@ -50,7 +50,7 @@ if(!check_function_exists("exec_db_mysql_imp_fetch_all")) {
if(!check_function_exists("close_db_mysql_imp_connect")) { if(!check_function_exists("close_db_mysql_imp_connect")) {
function close_db_mysql_imp_connect() { function close_db_mysql_imp_connect() {
$dbc = get_scope("dbc"); $dbc = get_shared_var("dbc");
return mysqli_close($dbc); return mysqli_close($dbc);
} }
} }

View File

@ -53,7 +53,7 @@ if(!check_function_exists("exec_db_mysql_old_fetch_all")) {
if(!check_function_exists("close_db_mysql_old_connect")) { if(!check_function_exists("close_db_mysql_old_connect")) {
function close_db_mysql_old_connect() { function close_db_mysql_old_connect() {
$dbc = get_scope("dbc"); $dbc = get_shared_var("dbc");
return mysql_close($dbc); return mysql_close($dbc);
} }
} }

View File

@ -130,7 +130,7 @@ if(!check_function_exists("exec_db_oracle_query")) {
if(!check_function_exists("close_db_oracle_connect")) { if(!check_function_exists("close_db_oracle_connect")) {
function close_db_oracle_connect() { function close_db_oracle_connect() {
$dbc = get_scope("dbc"); $dbc = get_shared_var("dbc");
if(!check_db_oracle_installed()) { if(!check_db_oracle_installed()) {
show_errors(); show_errors();

View File

@ -9,7 +9,7 @@
if(!check_function_exists("get_obfuscator")) { if(!check_function_exists("get_obfuscator")) {
function get_obfuscator() { function get_obfuscator() {
$obfuscator = rand(1, 15); $obfuscator = rand(1, 15);
set_scope("obfuscator", $obfuscator); set_shared_var("obfuscator", $obfuscator);
return $obfuscator; return $obfuscator;
} }
} }

View File

@ -57,8 +57,8 @@ if(!check_function_exists("zabbix_authenticate")) {
} }
// set connection to global scope // set connection to global scope
set_scope("zabbix_api_url", $zabbix_api_url); set_shared_var("zabbix_api_url", $zabbix_api_url);
set_scope("zabbix_auth", get_property_value("result", $response)); set_shared_var("zabbix_auth", get_property_value("result", $response));
return $response; return $response;
} }
@ -70,8 +70,8 @@ if(!check_function_exists("zabbix_get_hosts")) {
$response = false; $response = false;
// get zabbix authentication // get zabbix authentication
$zabbix_api_url = get_scope("zabbix_api_url"); $zabbix_api_url = get_shared_var("zabbix_api_url");
$zabbix_auth = get_scope("zabbix_auth"); $zabbix_auth = get_shared_var("zabbix_auth");
// connect to zabbix server // connect to zabbix server
if(loadHelper("webpagetool")) { if(loadHelper("webpagetool")) {
@ -105,8 +105,8 @@ if(!check_function_exists("zabbix_get_items")) {
$response = false; $response = false;
// get zabbix authentication // get zabbix authentication
$zabbix_api_url = get_scope("zabbix_api_url"); $zabbix_api_url = get_shared_var("zabbix_api_url");
$zabbix_auth = get_scope("zabbix_auth"); $zabbix_auth = get_shared_var("zabbix_auth");
// connect to zabbix server // connect to zabbix server
if(loadHelper("webpagetool")) { if(loadHelper("webpagetool")) {
@ -140,8 +140,8 @@ if(!check_function_exists("zabbix_get_problems")) {
$response = false; $response = false;
// get zabbix authentication // get zabbix authentication
$zabbix_api_url = get_scope("zabbix_api_url"); $zabbix_api_url = get_shared_var("zabbix_api_url");
$zabbix_auth = get_scope("zabbix_auth"); $zabbix_auth = get_shared_var("zabbix_auth");
// connect to zabbix server // connect to zabbix server
if(loadHelper("webpagetool")) { if(loadHelper("webpagetool")) {
@ -177,8 +177,8 @@ if(!check_function_exists("zabbix_get_triggers")) {
$response = false; $response = false;
// get zabbix authentication // get zabbix authentication
$zabbix_api_url = get_scope("zabbix_api_url"); $zabbix_api_url = get_shared_var("zabbix_api_url");
$zabbix_auth = get_scope("zabbix_auth"); $zabbix_auth = get_shared_var("zabbix_auth");
if(loadHelper("webpagetool")) { if(loadHelper("webpagetool")) {
$response = get_web_json($zabbix_api_url, "jsonrpc2.cache", array( $response = get_web_json($zabbix_api_url, "jsonrpc2.cache", array(
@ -208,8 +208,8 @@ if(!check_function_exists("zabbix_get_alerts")) {
$response = false; $response = false;
// get zabbix authentication // get zabbix authentication
$zabbix_api_url = get_scope("zabbix_api_url"); $zabbix_api_url = get_shared_var("zabbix_api_url");
$zabbix_auth = get_scope("zabbix_auth"); $zabbix_auth = get_shared_var("zabbix_auth");
if(loadHelper("webpagetool")) { if(loadHelper("webpagetool")) {
$params = array( $params = array(
@ -257,8 +257,8 @@ if(!check_function_exists("zabbix_get_records")) {
} }
// get zabbix authentication // get zabbix authentication
$zabbix_api_url = get_scope("zabbix_api_url"); $zabbix_api_url = get_shared_var("zabbix_api_url");
$zabbix_auth = get_scope("zabbix_auth"); $zabbix_auth = get_shared_var("zabbix_auth");
// set time range variables // set time range variables
$time_from = get_current_timestamp(array("now" => $now_dt, "adjust" => $adjust)); $time_from = get_current_timestamp(array("now" => $now_dt, "adjust" => $adjust));

View File

@ -1,7 +1,8 @@
<?php <?php
/** /**
* @file base.php * @file base.php
* @date 2018-04-13 * @created_on 2018-04-13
* @updated_on 2020-01-28
* @author Go Namhyeon <gnh1201@gmail.com> * @author Go Namhyeon <gnh1201@gmail.com>
* @brief Base module * @brief Base module
*/ */
@ -35,26 +36,26 @@ if(!(check_invalid_function("check_function_exists") < 0)) {
} }
} }
// set scope // set shared var
if(!check_function_exists("set_scope")) { if(!check_function_exists("set_shared_var")) {
function set_scope($k, $v) { function set_shared_var($k, $v) {
global $scope; global $shared_vars;
$scope[$k] = $v; $shared_vars[$k] = $v;
} }
} }
// get scope // get shared var
if(!check_function_exists("get_scope")) { if(!check_function_exists("get_shared_var")) {
function get_scope($k) { function get_shared_var($k) {
global $scope; global $shared_vars;
return array_key_exists($k, $scope) ? $scope[$k] : null; return array_key_exists($k, $shared_vars) ? $shared_vars[$k] : null;
} }
} }
// register loaded resources // register loaded resources
if(!check_function_exists("register_loaded")) { if(!check_function_exists("register_loaded")) {
function register_loaded($k, $v) { function register_loaded($k, $v) {
$loaded = get_scope("loaded"); $loaded = get_shared_var("loaded");
if(array_key_exists($k, $loaded)) { if(array_key_exists($k, $loaded)) {
if(is_array($loaded[$k])) { if(is_array($loaded[$k])) {
@ -62,7 +63,7 @@ if(!check_function_exists("register_loaded")) {
} }
} }
set_scope("loaded", $loaded); set_shared_var("loaded", $loaded);
} }
} }
@ -290,40 +291,39 @@ if(!check_function_exists("check_is_empty")) {
} }
} }
// error handler // error handler (set error)
if(!check_function_exists("set_error")) { if(!check_function_exists("set_error")) {
function set_error($msg, $code="ERROR") { function set_error($msg, $code="ERROR") {
global $scope; global $shared_vars;
$scope['errors'][] = $code . ": " . $msg; $shared_vars['errors'][] = $code . ": " . $msg;
} }
} }
// error handler (get errors)
if(!check_function_exists("get_errors")) { if(!check_function_exists("get_errors")) {
function get_errors($d=false, $e=false) { // d: display, e: exit function get_errors($d=false, $e=false) { // d: display, e: exit
global $scope; global $shared_vars;
$errors = $scope['errors']; return $shared_vars['errors'];
if($d === true) {
foreach($errors as $err) {
echo $err . PHP_EOL;
}
}
if($e === true) {
exit;
}
return $errors;
} }
} }
// error handler (show errors)
if(!check_function_exists("show_errors")) { if(!check_function_exists("show_errors")) {
function show_errors($exit=true) { function show_errors($exit=true) {
return get_errors(true, $exit); $errors = get_errors();
foreach($errors as $err) {
echo $err . DOC_EOL;
}
if($exit !== false) {
exit;
}
} }
} }
if(!check_function_exists("do_error")) { // error handler (trigger error)
function do_error($msg, $code="ERROR") { if(!check_function_exists("trigger_error")) {
function trigger_error($msg, $code="ERROR") {
set_error($msg, $code); set_error($msg, $code);
show_errors(); show_errors();
} }
@ -348,7 +348,7 @@ if(!check_function_exists("get_property_value")) {
if(!check_function_exists("get_routes")) { if(!check_function_exists("get_routes")) {
function get_routes() { function get_routes() {
$loaded = get_scope("loaded"); $loaded = get_shared_var("loaded");
return $loaded['route']; return $loaded['route'];
} }
} }
@ -377,5 +377,5 @@ $loaded = array(
$errors = array(); $errors = array();
set_scope("loaded", $loaded); set_shared_var("loaded", $loaded);
set_scope("errors", $errors); set_shared_var("errors", $errors);

View File

@ -35,13 +35,13 @@ if(!check_function_exists("read_config")) {
if(!check_function_exists("get_config")) { if(!check_function_exists("get_config")) {
function get_config() { function get_config() {
$config = get_scope("config"); $config = get_shared_var("config");
if(!is_array($config)) { if(!is_array($config)) {
set_scope("config", read_config()); set_shared_var("config", read_config());
} }
return get_scope("config"); return get_shared_var("config");
} }
} }

View File

@ -70,9 +70,9 @@ if(!check_function_exists("exec_stmt_query")) {
if(!check_function_exists("get_dbc_object")) { if(!check_function_exists("get_dbc_object")) {
function get_dbc_object($renew=false) { function get_dbc_object($renew=false) {
if($renew) { if($renew) {
set_scope("dbc", get_db_connect()); set_shared_var("dbc", get_db_connect());
} }
return get_scope("dbc"); return get_shared_var("dbc");
} }
} }
@ -1061,9 +1061,9 @@ if(!check_function_exists("exec_db_temp_end")) {
// close db connection // close db connection
if(!check_function_exists("close_db_connect")) { if(!check_function_exists("close_db_connect")) {
function close_db_connect() { function close_db_connect() {
$dbc = get_scope("dbc"); $dbc = get_shared_var("dbc");
$dbc->close(); $dbc->close();
set_scope("dbc", null); set_shared_var("dbc", null);
} }
} }

View File

@ -166,13 +166,13 @@ if(!check_function_exists("read_requests")) {
if(!check_function_exists("get_requests")) { if(!check_function_exists("get_requests")) {
function get_requests() { function get_requests() {
$requests = get_scope("requests"); $requests = get_shared_var("requests");
if(!is_array($requests)) { if(!is_array($requests)) {
set_scope("requests", read_requests()); set_shared_var("requests", read_requests());
} }
return get_scope("requests"); return get_shared_var("requests");
} }
} }