Example #1
0
 /**
  * @brief  语言识别主函数
  * 识别出来的locale, instance存于成员 self::$_locale, self::$_instance 中
  */
 public static function checkLocale()
 {
     self::_init();
     self::$_locale = '';
     self::$_instance = '';
     self::$_cur_strategy = '';
     foreach (self::$_strategy as $_v) {
         $strategyName = $_v;
         $className = ucfirst($_v);
         if (in_array($_v, self::$_default_strategy)) {
             $className = "Bd_Global_Strategy_{$_v}";
         }
         if (!class_exists($className)) {
             if (in_array($_v, self::$_default_strategy)) {
                 require_once dirname(__FILE__) . '/global/strategy/' . ucfirst($_v) . '.php';
             } else {
                 // 产品线自定义类
                 $arr = explode('_', $className);
                 $fileName = array_pop($arr);
                 $path = $arr ? strtolower(implode('/', $arr)) . "/{$fileName}" : $fileName;
                 require_once dirname(__FILE__) . '/../' . $path . '.php';
             }
         }
         if (!class_exists($className)) {
             self::_fatalErr("strategy class {$className} not found, please check locale.conf");
         }
         $obj = new $className();
         if (!$obj instanceof Bd_Global_Strategy_Base) {
             self::_fatalErr("class {$className} must extends from Bd_Global_Strategy_Base.");
         }
         if ($obj->run()) {
             $_cur_locale = Bd_Global_Strategy_Base::getLocale();
             if ($_cur_locale) {
                 //如果识别出来的不合法,忽略,进入下一策略
                 if (self::_checkLocaleValid($_cur_locale)) {
                     //如果策略有识别instance,合法既识别成功
                     self::$_locale = $_cur_locale;
                     self::$_cur_strategy = $strategyName;
                     break;
                 } else {
                     //locale 不合法
                     self::$_locale = '';
                     self::$_instance = '';
                     self::$_cur_strategy = '';
                     Bd_Log::warning("strategy {$strategyName} locale \"{$_cur_locale}\" is not valid, ignored!");
                 }
             }
         }
     }
     if (empty(self::$_locale)) {
         self::$_locale = self::$_default_locale;
     }
     //locale => instance
     if (empty(self::$_instance)) {
         self::$_instance = self::getInstanceFromLocale(self::$_locale);
     }
     $ret = self::_end();
     return $ret;
 }