Example #1
0
 /**
  * Initialize the application, configure the settings, inject dependencies
  * Adjust the settings necessary for running the system
  */
 public function init()
 {
     if ($this->_init) {
         return;
     }
     date_default_timezone_set($this->_config->get('timezone'));
     /*
      * Init cache connection
      */
     $this->_initCache();
     /*
      * Init database connection
      */
     $conManager = $this->_initDb();
     /*
      * Apply configs
      */
     Filter::setDelimiter($this->_config->get('urlDelimiter'));
     Request::setDelimiter($this->_config->get('urlDelimiter'));
     Request::setExtension($this->_config->get('urlExtension'));
     Request::setRoot($this->_config->get('wwwroot'));
     Resource::setCachePaths($this->_config->get('jsCacheSysUrl'), $this->_config->get('jsCacheSysPath'));
     Resource::setDocRoot($this->_config->get('docroot'));
     Resource::setResourceRoot($this->_config->get('wwwroot'));
     Utils::setSalt($this->_config->get('salt'));
     /*
      * Init lang dictionary (Lazy Load)
      */
     $lang = $this->_config->get('language');
     Lang::addDictionaryLoader($lang, $this->_config->get('docroot') . '/system/lang/' . $lang . '.php', Config::File_Array);
     Lang::setDefaultDictionary($this->_config->get('language'));
     $eventManager = new Eventmanager();
     if ($this->_cache) {
         $eventManager->setCache($this->_cache);
         Resource::setCache($this->_cache);
         Template::setCache($this->_cache);
         if ($this->_config->offsetExists('template_check_mtime')) {
             Template::checkMtime($this->_config->get('template_check_mtime'));
         }
     }
     /*
      * Prepare Db object storage
      */
     $objectStore = new Db_Object_Store();
     $objectStore->setEventManager($eventManager);
     $objectStore->setLinksObjectName($this->_config->get('orm_links_object'));
     $objectStore->setHistoryObject($this->_config->get('orm_history_object'));
     $objectStore->setVersionObject($this->_config->get('orm_version_object'));
     /*
      * Prepare models
      */
     Model::setDataCache($this->_cache);
     Model::setGlobalHardcacheTime($this->_config->get('frontend_hardcache'));
     Model::setGlobalObjectStore($objectStore);
     Model::setDefaultDbManager($conManager);
     /*
      * Prepare Db_Object
      */
     $translator = new Db_Object_Config_Translator($this->_config->get('lang_path') . $this->_config->get('language') . '/objects.php');
     $translator->addTranslations(array($this->_config->get('lang_path') . $this->_config->get('language') . '/system_objects.php'));
     Db_Object_Config::setConfigPath($this->_config->get('object_configs'));
     Db_Object_Config::setTranslator($translator);
     if ($this->_config->get('db_object_error_log')) {
         $log = new Log_File($this->_config->get('db_object_error_log_path'));
         /*
          * Switch to Db_Object error log
          */
         if ($this->_config->get('erorr_log_object')) {
             $errorModel = Model::factory($this->_config->get('erorr_log_object'));
             $errorTable = $errorModel->table(true);
             $errorDb = $errorModel->getDbConnection();
             $logOrmDb = new Log_Db('db_object_error_log', $errorDb, $errorTable);
             $logModelDb = new Log_Db('model', $errorDb, $errorTable);
             Db_Object::setLog(new Log_Mixed($log, $logOrmDb));
             Model::setDefaultLog(new Log_Mixed($log, $logModelDb));
             $objectStore->setLog($logOrmDb);
         } else {
             Db_Object::setLog($log);
             Model::setDefaultLog($log);
             $objectStore->setLog($log);
         }
     }
     /*
      * Prepare dictionaries
      */
     Dictionary::setConfigPath($this->_config->get('dictionary'));
     /*
      * Prepare Controllers
      */
     Controller::setDefaultDb($this->_db);
     /*
      * Prepare Externals
      */
     if ($this->_config->get('allow_externals')) {
         $this->_initExternals();
     }
     $this->_init = true;
 }
Example #2
0
 /**
  * Get possible actions from Controller class.
  * Note! Code accelerator (eaccelerator, apc, xcache, etc ) should be disabled to get comment line.
  * Method returns only public methods that ends with "Action" 
  * @param string $controllerName
  * @return array like array(
  * 		array(
  * 			'name' => action name without "Action" postfix
  * 			'comment'=> doc comment
  * 		)
  * )
  */
 public static function getPossibleActions($controllerName)
 {
     $manager = new Backend_Modules_Manager();
     $appCfg = Registry::get('main', 'config');
     $designerConfig = Config::factory(Config::File_Array, $appCfg->get('configs') . 'designer.php');
     $templates = $designerConfig->get('templates');
     $reflector = new ReflectionClass($controllerName);
     if (!$reflector->isSubclassOf('Backend_Controller') && !$reflector->isSubclassOf('Frontend_Controller')) {
         return array();
     }
     $actions = array();
     $methods = $reflector->getMethods(ReflectionMethod::IS_PUBLIC);
     $url = array();
     if ($reflector->isSubclassOf('Backend_Controller')) {
         $url[] = $templates['adminpath'];
         $url[] = $manager->getModuleName($controllerName);
     } elseif ($reflector->isSubclassOf('Frontend_Controller')) {
         if ($appCfg['frontend_router_type'] == 'module') {
             $module = self::_moduleByClass($controllerName);
             if ($module !== false) {
                 $urlcode = Model::factory('Page')->getCodeByModule($module);
                 if ($urlcode !== false) {
                     $url[] = $urlcode;
                 }
             }
         } elseif ($appCfg['frontend_router_type'] == 'path') {
             $paths = explode('_', str_replace(array('Frontend_'), '', $controllerName));
             $pathsCount = count($paths) - 1;
             if ($paths[$pathsCount] === 'Controller') {
                 $paths = array_slice($paths, 0, $pathsCount);
             }
             $url = array_merge($url, $paths);
         } elseif ($appCfg['frontend_router_type'] == 'config') {
             $urlCode = self::_moduleByClass($controllerName);
             if ($urlCode !== false) {
                 $url[] = $urlCode;
             }
         }
     }
     if (!empty($methods)) {
         Request::setDelimiter($templates['urldelimiter']);
         Request::setRoot($templates['wwwroot']);
         foreach ($methods as $method) {
             if (substr($method->name, -6) !== 'Action') {
                 continue;
             }
             $actionName = substr($method->name, 0, -6);
             $paths = $url;
             $paths[] = $actionName;
             $actions[] = array('name' => $actionName, 'code' => $method->name, 'url' => Request::url($paths, false), 'comment' => self::_clearDocSymbols($method->getDocComment()));
         }
         Request::setDelimiter($appCfg['urlDelimiter']);
         Request::setRoot($appCfg['wwwroot']);
     }
     return $actions;
 }