コード例 #1
0
 /**
  * Handles autoloading of classes
  *
  * @param      string A class name.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public static function __autoload($class)
 {
     if (self::$autoloads === null) {
         self::$autoloads = array();
         // catch parse errors of autoload.xml
         try {
             $cfg = AgaviConfig::get('core.config_dir') . '/autoload.xml';
             if (!is_readable($cfg)) {
                 $cfg = AgaviConfig::get('core.system_config_dir') . '/autoload.xml';
                 if (!is_readable($cfg)) {
                     return;
                 }
             }
             self::$autoloads = (include AgaviConfigCache::checkConfig($cfg));
             // if(class_exists($class, false)) {
             // 	return;
             // }
         } catch (Exception $e) {
             trigger_error($e->getMessage(), E_USER_ERROR);
         }
     }
     if (isset(self::$autoloads[$class])) {
         // class exists, let's include it
         require self::$autoloads[$class];
     }
     /*
     	If the class doesn't exist in autoload.xml there's not a lot we can do. Because
     	PHP's class_exists resorts to __autoload we cannot throw exceptions
     	for this might break some 3rd party lib autoloading mechanism.
     */
 }
コード例 #2
0
 /**
  * Initialize a module and load its autoload, module config etc.
  *
  * @param      string The name of the module to initialize.
  *
  * @author     Felix Gilcher <*****@*****.**>
  * @since      1.0.0
  */
 public function initializeModule($moduleName)
 {
     $lowerModuleName = strtolower($moduleName);
     if (null === AgaviConfig::get('modules.' . $lowerModuleName . '.enabled')) {
         // set some defaults first
         AgaviConfig::fromArray(array('modules.' . $lowerModuleName . '.agavi.action.path' => '%core.module_dir%/${moduleName}/actions/${actionName}Action.class.php', 'modules.' . $lowerModuleName . '.agavi.cache.path' => '%core.module_dir%/${moduleName}/cache/${actionName}.xml', 'modules.' . $lowerModuleName . '.agavi.template.directory' => '%core.module_dir%/${module}/templates', 'modules.' . $lowerModuleName . '.agavi.validate.path' => '%core.module_dir%/${moduleName}/validate/${actionName}.xml', 'modules.' . $lowerModuleName . '.agavi.view.path' => '%core.module_dir%/${moduleName}/views/${viewName}View.class.php', 'modules.' . $lowerModuleName . '.agavi.view.name' => '${actionName}${viewName}'));
         // include the module configuration
         // loaded only once due to the way load() (former import()) works
         if (is_readable(AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config/module.xml')) {
             include_once AgaviConfigCache::checkConfig(AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config/module.xml');
         } else {
             AgaviConfig::set('modules.' . $lowerModuleName . '.enabled', true);
         }
         $moduleAutoload = AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config/autoload.xml';
         if (is_readable($moduleAutoload)) {
             Agavi::$autoloads = array_merge(Agavi::$autoloads, include AgaviConfigCache::checkConfig($moduleAutoload));
         }
         if (AgaviConfig::get('modules.' . $lowerModuleName . '.enabled')) {
             $moduleConfigHandlers = AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config/config_handlers.xml';
             if (is_readable($moduleConfigHandlers)) {
                 AgaviConfigCache::addConfigHandlersFile($moduleConfigHandlers);
             }
         }
     }
     if (!AgaviConfig::get('modules.' . $lowerModuleName . '.enabled')) {
         throw new AgaviDisabledModuleException(sprintf('The module "%1$s" is disabled.', $moduleName));
     }
     // check for a module config.php
     $moduleConfig = AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config.php';
     if (is_readable($moduleConfig)) {
         require_once $moduleConfig;
     }
 }