Broker.php

00001 <?php
00011 class Dsao_Module_Broker
00012 {
00016   const XML_MODULE_INFO_DIR = 'modules/meta/info';
00017 
00021   protected static $_instance = null;
00022 
00026   protected $_modulesActive = array();
00027 
00031   protected $_modulesNotActive = array();
00032 
00038   protected function __construct()
00039   {
00040     $modulesLoader = new Dsao_Xml_Loader(XML_DIR.self::XML_MODULE_INFO_DIR);
00041 
00042     // Module durchgehen
00043     foreach ($modulesLoader->getXmlObjects() as $object)
00044     {
00045       // Modul instanziieren
00046       $module = new Dsao_Module($object->name, (bool) $object->active);
00047 
00048       // Zu internen Arrays hinzufügen
00049       if ($module->isActive())
00050       {
00051         $this->_modulesActive[$module->getName()] = $module;
00052       }
00053       else
00054       {
00055         $this->_modulesNotActive[$module->getName()] = $module;
00056       }
00057     }
00058   }
00059 
00065   public static function getInstance()
00066   {
00067     // Falls Instanz noch nicht initialisiert
00068     if (null === self::$_instance)
00069     {
00070       $cacheLoader = new Dsao_Cache_Loader('File',
00071         array('automatic_serialization' => true,
00072               'master_files' => array(XML_DIR.self::XML_MODULE_INFO_DIR)));
00073       $cache = $cacheLoader->getCache();
00074 
00075       // Falls Modulmanager nicht im Cache vorhanden
00076       if (!(self::$_instance = $cache->load('moduleBroker')))
00077       {
00078         self::$_instance = new self();
00079 
00080         // Alle von den Modulen abhängigen Cache-Einträge entfernen
00081         $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('module'));
00082 
00083         $cache->save(self::$_instance, 'moduleBroker');
00084       }
00085     }
00086 
00087     return self::$_instance;
00088   }
00089 
00096   public function getModule($name)
00097   {
00098     $name = (string) $name;
00099 
00100     // Falls Modul aktives Modul
00101     if (isset($this->_modulesActive[$name]))
00102     {
00103       return $this->_modulesActive[$name];
00104     }
00105     // Falls Modul nicht aktives Modul
00106     else if (isset($this->_modulesNotActive[$name]))
00107     {
00108       return $this->_modulesNotActive[$name];
00109     }
00110     // Ansonsten ist Modul nicht vorhanden, Exception werfen
00111     else
00112     {
00113       throw new Dsao_Exception(array(
00114         'message' => 'dsao_module_manager_invalid_module',
00115         'variables' => array('name' => $name)
00116       ));
00117     }
00118   }
00119 
00125   public function getModules($namesOnly = false)
00126   {
00127     return $namesOnly
00128     ? array_keys(array_merge($this->_modulesActive, $this->_modulesNotActive))
00129     : array_merge($this->_modulesActive, $this->_modulesNotActive);
00130   }
00131 
00137   public function getModulesActive($namesOnly = false)
00138   {
00139     return $namesOnly ? array_keys($this->_modulesActive)
00140       : $this->_modulesActive;
00141   }
00142 
00148   public function getModulesNotActive($namesOnly = false)
00149   {
00150     return $namesOnly ? array_keys($this->_modulesNotActive)
00151       : $this->_modulesNotActive;
00152   }
00153 }

Erzeugt am Fri Sep 18 19:04:11 2009 für DSA online - Morgendaemmerung von  doxygen 1.5.7.1