mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-09 20:12:14 +09:00
#19548441 ModuleHanlder::getModuleInstance 메소드 코드 정리
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@8102 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
2b1a752947
commit
d6e6e9ab67
1 changed files with 30 additions and 55 deletions
|
|
@ -424,21 +424,29 @@
|
||||||
**/
|
**/
|
||||||
function &getModuleInstance($module, $type = 'view', $kind = '') {
|
function &getModuleInstance($module, $type = 'view', $kind = '') {
|
||||||
|
|
||||||
$parent_module = $module;
|
|
||||||
if(__DEBUG__==3) $start_time = getMicroTime();
|
if(__DEBUG__==3) $start_time = getMicroTime();
|
||||||
|
|
||||||
|
$kind = strtolower($kind);
|
||||||
|
$type = strtolower($type);
|
||||||
|
|
||||||
|
$kinds = explode(' ', 'svc admin');
|
||||||
|
if(!in_array($kind, $kinds)) $kind = $kinds[0];
|
||||||
|
|
||||||
$key = $module.'.'.($kind!='admin'?'':'admin').'.'.$type;
|
$key = $module.'.'.($kind!='admin'?'':'admin').'.'.$type;
|
||||||
|
|
||||||
if(is_array($GLOBALS['__MODULE_EXTEND__']) && array_key_exists($key, $GLOBALS['__MODULE_EXTEND__'])) {
|
if(is_array($GLOBALS['__MODULE_EXTEND__']) && array_key_exists($key, $GLOBALS['__MODULE_EXTEND__'])) {
|
||||||
$module = $extend_module = $GLOBALS['__MODULE_EXTEND__'][$key];
|
$module = $extend_module = $GLOBALS['__MODULE_EXTEND__'][$key];
|
||||||
}else{
|
}else{
|
||||||
unset($parent_module);
|
unset($parent_module);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if there is no instance of the module in global variable, create a new one
|
||||||
|
if(!$GLOBALS['_loaded_module'][$module][$type][$kind]) {
|
||||||
|
$parent_module = $module;
|
||||||
|
|
||||||
$class_path = ModuleHandler::getModulePath($module);
|
$class_path = ModuleHandler::getModulePath($module);
|
||||||
if(!is_dir(FileHandler::getRealPath($class_path))) return NULL;
|
if(!is_dir(FileHandler::getRealPath($class_path))) return NULL;
|
||||||
|
|
||||||
// if there is no instance of the module in global variable, create a new one
|
|
||||||
if(!$GLOBALS['_loaded_module'][$module][$type][$kind]) {
|
|
||||||
// Get base class name and load the file contains it
|
// Get base class name and load the file contains it
|
||||||
if(!class_exists($module)) {
|
if(!class_exists($module)) {
|
||||||
$high_class_file = sprintf('%s%s%s.class.php', _XE_PATH_,$class_path, $module);
|
$high_class_file = sprintf('%s%s%s.class.php', _XE_PATH_,$class_path, $module);
|
||||||
|
|
@ -447,63 +455,30 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the object's name
|
// Get the object's name
|
||||||
switch($type) {
|
$types = explode(' ', 'view controller model api wap mobile class');
|
||||||
case 'controller' :
|
if(!in_array($type, $types)) $type = $types[0];
|
||||||
if($kind == 'admin') {
|
if($type == 'class') {
|
||||||
$instance_name = sprintf("%sAdmin%s",$module,"Controller");
|
$instance_name = '%s';
|
||||||
$class_file = sprintf('%s%s.admin.%s.php', $class_path, $module, $type);
|
$class_file = '%s%s.%s.php';
|
||||||
} else {
|
} elseif($kind == 'admin' && array_search($type, $types) < 3) {
|
||||||
$instance_name = sprintf("%s%s",$module,"Controller");
|
$instance_name = '%sAdmin%s';
|
||||||
$class_file = sprintf('%s%s.%s.php', $class_path, $module, $type);
|
$class_file = '%s%s.admin.%s.php';
|
||||||
|
} else{
|
||||||
|
$instance_name = '%s%s';
|
||||||
|
$class_file = '%s%s.%s.php';
|
||||||
}
|
}
|
||||||
break;
|
$instance_name = sprintf($instance_name, $module, ucfirst($type));
|
||||||
case 'model' :
|
$class_file = sprintf($class_file, $class_path, $module, $type);
|
||||||
if($kind == 'admin') {
|
|
||||||
$instance_name = sprintf("%sAdmin%s",$module,"Model");
|
|
||||||
$class_file = sprintf('%s%s.admin.%s.php', $class_path, $module, $type);
|
|
||||||
} else {
|
|
||||||
$instance_name = sprintf("%s%s",$module,"Model");
|
|
||||||
$class_file = sprintf('%s%s.%s.php', $class_path, $module, $type);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'api' :
|
|
||||||
$instance_name = sprintf("%s%s",$module,"API");
|
|
||||||
$class_file = sprintf('%s%s.api.php', $class_path, $module);
|
|
||||||
break;
|
|
||||||
case 'wap' :
|
|
||||||
$instance_name = sprintf("%s%s",$module,"WAP");
|
|
||||||
$class_file = sprintf('%s%s.wap.php', $class_path, $module);
|
|
||||||
break;
|
|
||||||
case 'mobile' :
|
|
||||||
$instance_name = sprintf("%s%s",$module,"Mobile");
|
|
||||||
$class_file = sprintf("%s%s.mobile.php", $class_path, $module);
|
|
||||||
break;
|
|
||||||
case 'class' :
|
|
||||||
$instance_name = $module;
|
|
||||||
$class_file = sprintf('%s%s.class.php', $class_path, $module);
|
|
||||||
break;
|
|
||||||
default :
|
|
||||||
$type = 'view';
|
|
||||||
if($kind == 'admin') {
|
|
||||||
$instance_name = sprintf("%sAdmin%s",$module,"View");
|
|
||||||
$class_file = sprintf('%s%s.admin.view.php', $class_path, $module, $type);
|
|
||||||
} else {
|
|
||||||
$instance_name = sprintf("%s%s",$module,"View");
|
|
||||||
$class_file = sprintf('%s%s.view.php', $class_path, $module, $type);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$class_file = FileHandler::getRealPath($class_file);
|
$class_file = FileHandler::getRealPath($class_file);
|
||||||
|
|
||||||
// Get the name of the class file
|
// Get the name of the class file
|
||||||
if(!file_exists($class_file)) return NULL;
|
if(!is_readable($class_file)) return NULL;
|
||||||
|
|
||||||
// Create an instance with eval function
|
// Create an instance with eval function
|
||||||
require_once($class_file);
|
require_once($class_file);
|
||||||
if(!class_exists($instance_name)) return NULL;
|
if(!class_exists($instance_name)) return NULL;
|
||||||
$eval_str = sprintf('$oModule = new %s();', $instance_name);
|
$tmp_fn = create_function('', "return new {$instance_name}();");
|
||||||
@eval($eval_str);
|
$oModule = $tmp_fn();
|
||||||
if(!is_object($oModule)) return NULL;
|
if(!is_object($oModule)) return NULL;
|
||||||
|
|
||||||
// Load language files for the class
|
// Load language files for the class
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue