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")) {
function close_db_mysql_imp_connect() {
$dbc = get_scope("dbc");
$dbc = get_shared_var("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")) {
function close_db_mysql_old_connect() {
$dbc = get_scope("dbc");
$dbc = get_shared_var("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")) {
function close_db_oracle_connect() {
$dbc = get_scope("dbc");
$dbc = get_shared_var("dbc");
if(!check_db_oracle_installed()) {
show_errors();

View File

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

View File

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

View File

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

View File

@ -35,13 +35,13 @@ if(!check_function_exists("read_config")) {
if(!check_function_exists("get_config")) {
function get_config() {
$config = get_scope("config");
$config = get_shared_var("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")) {
function get_dbc_object($renew=false) {
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
if(!check_function_exists("close_db_connect")) {
function close_db_connect() {
$dbc = get_scope("dbc");
$dbc = get_shared_var("dbc");
$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")) {
function get_requests() {
$requests = get_scope("requests");
$requests = get_shared_var("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");
}
}