diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-10-18 09:23:59 -0700 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-10-18 09:23:59 -0700 |
commit | 4949a2ce0b5daca7afe86a261be447440fce7eff (patch) | |
tree | 3e6f407d54001462c5f600f577c851d02b03a10c | |
parent | 661369b50f08c6256ed6f90922d0a9eeb6d4dad2 (diff) |
Optimize the get method to retrieve the module information from the loaded modules. In addition add a method "info" to return the module information contained in the module.info file
-rw-r--r-- | modules/gallery/helpers/module.php | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index fe37f4f9..77ec6f63 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -50,8 +50,20 @@ class module_Core { * @param string $module_name */ static function get($module_name) { - // @todo can't easily use model_cache here because it throw an exception on missing models. - return ORM::factory("module", array("name" => $module_name)); + if (empty(self::$modules[$module_name])) { + return ORM::factory("module", array("name" => $module_name)); + } + return self::$modules[$module_name]; + } + + /** + * Get the information about a module + * @returns ArrayObject containing the module information from the module.info file or false if + * not found + */ + static function info($module_name) { + $module_list = self::available(); + return isset($module_list->$module_name) ? $module_list->$module_name : false; } /** @@ -79,7 +91,8 @@ class module_Core { $modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); foreach (glob(MODPATH . "*/module.info") as $file) { $module_name = basename(dirname($file)); - $modules->$module_name = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); + $modules->$module_name = + new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); $m =& $modules->$module_name; $m->installed = self::is_installed($module_name); $m->active = self::is_active($module_name); |