Skip to content

Commit de30ecf

Browse files
committed
NOISSUE, Adding the magic class value. a module can get a MVC object of module by special member value like $this->o{ModuleName}{Type} in each Module Class extended ModuleObject Class.
eg) $oDocumentModel = $this->oDocumentModel; instead of $oDocumentModel = getModel('document'); $oDocumentAdminController = $this->oDocumentAdminController; instead of $oDocumentAdminController = getAdminController('document');
1 parent bc47f19 commit de30ecf

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

classes/module/ModuleObject.class.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class ModuleObject extends Object
2727
var $ajaxRequestMethod = array('XMLRPC', 'JSON');
2828
var $gzhandler_enable = TRUE;
2929

30+
private static $_oModules = array();
31+
3032
/**
3133
* setter to set the name of module
3234
* @param string $module name of module
@@ -477,5 +479,24 @@ function proc()
477479
return true;
478480
}
479481

482+
function __get($name)
483+
{
484+
if($name{0} !== 'o' || !isset($name{7})) return NULL;
485+
if(isset(self::$_oModules[$name])) return self::$_oModules[$name];
486+
487+
$types = array('Model', 'Controller', 'View', 'AdminModel', 'AdminController', 'AdminView');
488+
foreach($types as $type)
489+
{
490+
$func = 'get' . $type;
491+
if(FALSE !== ($pos=strpos($name, $type)) && 2 < $pos && ($oModule = $func(strtolower(substr($name, 1, $pos-1)))))
492+
{
493+
self::$_oModules[$name] = $oModule;
494+
return $oModule;
495+
}
496+
}
497+
498+
return NULL;
499+
}
480500
}
481-
?>
501+
/* End of file ModuleObject.class.php */
502+
/* Location: ./classes/module/ModuleObject.class.php */

0 commit comments

Comments
 (0)