From 4283aaaada7fe30fadddede2cbd5f0adbdec3413 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Fri, 13 Apr 2018 14:04:25 +0900 Subject: [PATCH] Update base.php --- system/base.php | 86 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 15 deletions(-) diff --git a/system/base.php b/system/base.php index e211d7d..83dfb1d 100644 --- a/system/base.php +++ b/system/base.php @@ -1,4 +1,47 @@ + * @brief Base module + */ + +// set scope +if(!function_exists("set_scope")) { + function set_scope($k, $v) { + global $scope; + $scope[$k] = $v; + } +} + +// get scope +if(!function_exists("get_scope")) { + function get_scope($k) { + global $scope; + return array_key_exists($k, $scope) ? $scope[$k] : null; + } +} + +// register loaded resources +if(!function_exists("register_loaded")) { + function register_loaded($k, $v) { + global $scope; + if(array_key_exists($k, $scope['loaded'])) { + array_push($scope['loaded'][$k], $v); + } + } +} + +// sandbox for include function +if(!function_exists("include_isolate")) { + function include_isolate($file, $data=array()) { + if(count($data) > 0) { + extract($data); + } + return include($file); + } +} + // view render if(!function_exists('renderView')) { function renderView($name, $data=array()) { @@ -7,9 +50,13 @@ if(!function_exists('renderView')) { } // load view file - $viewfile = './view/' . $name . '.php'; - if(file_exists($viewfile)) { - include($viewfile); + $views = explode(';', $name); + foreach($views as $name2) { + $viewfile = './view/' . $name2 . '.php'; + if(file_exists($viewfile)) { + include_isolate($viewfile, $data); + register_loaded("view", $viewfile); + } } } } @@ -22,7 +69,8 @@ if(!function_exists('loadModule')) { foreach($modules as $name2) { $systemfile = './system/' . $name2 . '.php'; if(file_exists($systemfile)) { - include($systemfile); + include_isolate($systemfile); + register_loaded("view", $systemfile); } } } @@ -36,24 +84,23 @@ if(!function_exists('loadHelper')) { foreach($helpers as $name2) { $helperfile = './helper/' . $name2 . '.php'; if(file_exists($helperfile)) { - include($helperfile); + include_isolate($helperfile); + register_loaded("helper", $helperfile); } } } } // re-route -if(!function_exists('reRoute')) { - function reRoute($name, $data=array()) { - if(count($data) > 0) { - extract($data); - } - +if(!function_exists('loadRoute')) { + function loadRoute($name, $data=array()) { // load route file - $routefile = './route/' . $name . '.php'; - - if(file_exists($routefile)) { - include($routefile); + $routes = explode(";", $name); + foreach($routes as $name2) { + $routefile = './route/' . $name . '.php'; + if(file_exists($routefile)) { + include_isolate($routefile, $data); + } } } } @@ -140,3 +187,12 @@ if(!function_exists("nl2p")) { return $paragraphs; } } + +$scope = array(); + +set_scope("loaded", array( + "module" => array(), + "helper" => array(), + "view" => array(), + "route" => array(), +));