예제 #1
0
 /** Pre-dispatch routines */
 public function preDispatch()
 {
     UtilityComponent::setTimeLimit(0);
     $enabledModules = Zend_Registry::get('modulesEnable');
     if (Zend_Registry::get('configGlobal')->application->lang != 'en') {
         $translate = new Zend_Translate('csv', BASE_PATH . '/core/translation/fr-main.csv', 'en');
         Zend_Registry::set('translator', $translate);
         $translators = array();
         foreach ($enabledModules as $enabledModule) {
             if (file_exists(BASE_PATH . '/modules/' . $enabledModule . '/translation/fr-main.csv')) {
                 $translators[$enabledModule] = new Zend_Translate('csv', BASE_PATH . '/modules/' . $enabledModule . '/translation/fr-main.csv', 'en');
             } elseif (file_exists(BASE_PATH . '/privateModules/' . $enabledModule . '/translation/fr-main.csv')) {
                 $translators[$enabledModule] = new Zend_Translate('csv', BASE_PATH . '/privateModules/' . $enabledModule . '/translation/fr-main.csv', 'en');
             }
             Zend_Registry::set('translatorsModules', $translators);
         }
     }
     $configs = array();
     foreach ($enabledModules as $enabledModule) {
         if (file_exists(LOCAL_CONFIGS_PATH . '/' . $enabledModule . '.local.ini')) {
             $configs[$enabledModule] = new Zend_Config_Ini(LOCAL_CONFIGS_PATH . '/' . $enabledModule . '.local.ini', 'global');
         } elseif (file_exists(BASE_PATH . '/privateModules/' . $enabledModule . '/configs/module.ini')) {
             $configs[$enabledModule] = new Zend_Config_Ini(BASE_PATH . '/privateModules/' . $enabledModule . '/configs/module.ini', 'global');
         } else {
             $configs[$enabledModule] = new Zend_Config_Ini(BASE_PATH . '/modules/' . $enabledModule . '/configs/module.ini', 'global');
         }
     }
     Zend_Registry::set('configsModules', $configs);
     $forward = $this->getParam('forwardModule');
     $request = $this->getRequest();
     $response = $this->getResponse();
     if (!isset($forward) && $request->getModuleName() == 'default') {
         foreach ($configs as $key => $config) {
             if (file_exists(BASE_PATH . '/modules/' . $key . '/controllers/' . ucfirst($request->getControllerName()) . 'CoreController.php')) {
                 include_once BASE_PATH . '/modules/' . $key . '/controllers/' . ucfirst($request->getControllerName()) . 'CoreController.php';
                 $name = ucfirst($key) . '_' . ucfirst($request->getControllerName()) . 'CoreController';
                 $controller = new $name($request, $response);
                 if (method_exists($controller, $request->getActionName() . 'Action')) {
                     $this->forward($request->getActionName(), $request->getControllerName() . 'Core', $key, array('forwardModule' => true));
                 }
             } elseif (file_exists(BASE_PATH . '/privateModules/' . $key . '/controllers/' . ucfirst($request->getControllerName()) . 'CoreController.php')) {
                 include_once BASE_PATH . '/privateModules/' . $key . '/controllers/' . ucfirst($request->getControllerName()) . 'CoreController.php';
                 $name = ucfirst($key) . '_' . ucfirst($request->getControllerName()) . 'CoreController';
                 $controller = new $name($request, $response);
                 if (method_exists($controller, $request->getActionName() . 'Action')) {
                     $this->forward($request->getActionName(), $request->getControllerName() . 'Core', $key, array('forwardModule' => true));
                 }
             }
         }
     }
     parent::preDispatch();
     if (!$this->isDebug()) {
         $frontendOptions = array('automatic_serialization' => true, 'lifetime' => 86400, 'cache_id_prefix' => 'midas_');
         if (extension_loaded('memcached') || session_save_path() === 'Memcache') {
             $cache = Zend_Cache::factory('Core', 'Libmemcached', $frontendOptions, array());
         } elseif (extension_loaded('memcache')) {
             $cache = Zend_Cache::factory('Core', 'Memcached', $frontendOptions, array());
         } else {
             $cacheDir = UtilityComponent::getCacheDirectory() . '/db';
             if (is_dir($cacheDir) && is_writable($cacheDir)) {
                 $backendOptions = array('cache_dir' => $cacheDir);
                 $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
             }
         }
         if (isset($cache)) {
             Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
         }
     }
 }