Exemple #1
0
 /**
  * Find and load module
  * @param string $a_module
  * @return ZModule
  */
 public final function &module($a_module, $a_throw = false)
 {
     $mod_name = trim(strtolower($a_module));
     if (isset($this->m_modules[$mod_name]) or array_key_exists($mod_name, $this->m_modules)) {
         return $this->m_modules[$mod_name];
     }
     $this->emit(new ZEvent($this, 'preModule', $mod_name));
     $mod_dir = $this->getModule()->fromModuleDir($mod_name);
     if (!file_exists($mod_dir)) {
         if ($a_throw) {
             throw new ZModuleException('Module "' . $mod_name . '" not exist', ZControllerException::EXC_LOAD);
         }
     }
     if (file_exists($mod_dir) and is_dir($mod_dir)) {
         $module = null;
         try {
             $module = $this->_loadClass($mod_name, $this->m_modules, 'module', 'ZModule');
         } catch (ZLoaderException $e) {
             if ($a_throw) {
                 throw new ZModuleException($e->getMessage(), ZModuleException::EXC_LOAD);
             }
             $module = new ZModule($this->getModule(), $mod_name);
             $this->m_modules[$mod_name] = $module;
         }
         $module->initialize();
         $module->setFlag('initialized');
         $this->emit(new ZEvent($this, 'postModule', $mod_name, $module));
         return $module;
     }
     return Zoombi::$null;
 }
Exemple #2
0
 /**
  * Find and load module
  * @param string $a_module
  * @return ZModule
  */
 public final function &module($a_module)
 {
     $m = trim(strtolower($a_module));
     if (isset($this->m_modules[$m]) or array_key_exists($m, $this->m_modules)) {
         return $this->m_modules[$m];
     }
     $this->emit(new ZEvent($this, 'preModule', $m));
     //$p = $this->getModule()->getConfig()->getValue('module.directory_name', 'module') . Zoombi::DS . $m;
     //$d = $this->getModule()->fromBaseDir($p);
     $d = $this->getModule()->fromModuleDir($m);
     if (!file_exists($d)) {
         throw new ZModuleException('Module "' . $m . '" not exist', ZControllerException::EXC_LOAD);
     }
     if (file_exists($d) and is_dir($d)) {
         $mod = null;
         try {
             $mod = $this->_loadClass($m, $this->m_modules, 'module', 'ZModule');
         } catch (ZLoaderException $e) {
             switch ($e->getCode()) {
                 case ZLoaderException::EXC_NO_FILE:
                     $mod = new ZModule($this->getModule(), $m);
                     $this->m_modules[$m] =& $mod;
                     break;
                 default:
                     throw new ZModuleException($e->getMessage(), ZModuleException::EXC_LOAD);
                     break;
             }
         }
         $mod->setBaseDir($d)->setConfig($mod->fromConfigDir('config.php'))->initialize();
         $mod->setFlag('initialized');
         $this->emit(new ZEvent($this, 'postModule', $m, $mod));
         return $mod;
     }
     return Zoombi::$null;
 }