コード例 #1
0
 /**
  * 获得module配置,$name为空时返回当前module配置
  *
  * @param string $name module名称 默认为空
  * @param boolean $merge 合并默认值
  * @return array
  * @throws WindActionException
  * @throws WindException
  */
 public function getModules($name = '')
 {
     if ($name === '') {
         $name = $this->handlerAdapter->getModule();
     }
     $_module = $this->getConfig('modules', $name, array());
     if (!isset($_module['_verified']) || $_module['_verified'] !== true) {
         if (empty($_module)) {
             $_module = $this->getConfig('modules', 'pattern', array());
             $_pattern = !empty($_module);
         }
         $_module = WindUtility::mergeArray($this->defaultModule, $_module);
         if (isset($_pattern) && $_pattern) {
             $_keys = array_keys($_module);
             $_replace = array('{' . $this->handlerAdapter->getModuleKey() . '}' => $this->handlerAdapter->getModule(), '{' . $this->handlerAdapter->getControllerKey() . '}' => $this->handlerAdapter->getController(), '{' . $this->handlerAdapter->getActionKey() . '}' => $this->handlerAdapter->getAction());
             foreach ($_keys as $_key) {
                 if (strrchr($_key, '-') !== '-path') {
                     continue;
                 }
                 $_module[$_key] = strtr($_module[$_key], $_replace);
             }
         }
         $_module['_verified'] = true;
         $this->_config['modules'][$name] = $_module;
     }
     return $_module;
 }
コード例 #2
0
 /**
  * 获得module配置,$name为空时返回当前module配置
  * 
  * @param string $name
  *        module名称 默认为空
  * @param boolean $merge
  *        合并默认值
  * @return array
  * @throws WindActionException
  * @throws WindException
  */
 public function getModules($name = '')
 {
     if ($name === '') {
         $name = $this->handlerAdapter->getModule();
     }
     if ($name === 'pattern') {
         $name = $this->handlerAdapter->getDefaultModule();
     }
     if ($name === 'default') {
         return $this->_config['modules']['default'];
     }
     $_module = $this->getConfig('modules', $name, array());
     if (!isset($_module['_verified']) || $_module['_verified'] !== true) {
         if (empty($_module) && !empty($this->_config['modules']['pattern'])) {
             $_module = $this->_config['modules']['pattern'];
         }
         if ($_module) {
             $_module = WindUtility::mergeArray($this->_config['modules']['default'], $_module);
         } else {
             throw new WindException('Your request was not found on this server.', 404);
         }
         $_module_str = implode('#', $_module);
         if (strpos($_module_str, '{') !== false) {
             preg_match_all('/{(\\w+)}/i', $_module_str, $matches);
             if (!empty($matches[1])) {
                 $_replace = array();
                 foreach ($matches[1] as $key => $value) {
                     if ($value === $this->handlerAdapter->getModuleKey()) {
                         $_replace['{' . $value . '}'] = $this->handlerAdapter->getModule();
                     } elseif ($value === $this->handlerAdapter->getControllerKey()) {
                         $_replace['{' . $value . '}'] = $this->handlerAdapter->getController();
                     } elseif ($value === $this->handlerAdapter->getActionKey()) {
                         $_replace['{' . $value . '}'] = $this->handlerAdapter->getAction();
                     } else {
                         $_replace['{' . $value . '}'] = $this->request->getGet($value);
                     }
                 }
                 $_module_str = strtr($_module_str, $_replace);
                 $_module = array_combine(array_keys($_module), explode('#', $_module_str));
             }
         }
         $_module['_verified'] = true;
         $this->_config['modules'][$name] = $_module;
     }
     return $_module;
 }