Exemplo n.º 1
0
 public static function getInstance($param = null)
 {
     // 初始化Smarty自动加载
     if (!self::$isInit) {
         Bd_Autoloader::addClassMap(self::$smartyClassMap);
         self::$isInit = true;
     }
     // 从配置中读取参数
     if (!is_array($param)) {
         // 加载配置
         if (empty(self::$arrConf)) {
             self::$arrConf = Bd_Conf::getConf('/smarty/');
             if (empty(self::$arrConf)) {
                 self::$arrConf = null;
                 return null;
             }
         }
         // 取指定的配置组
         if ($param != null) {
             $param = self::$arrConf[$param];
             // 不存在则出错
             if (!$param) {
                 return null;
             }
         } else {
             $param = current(self::$arrConf);
         }
     }
     // new一个smarty
     $smarty = new Smarty();
     // 根据参数初始化该smarty对象
     $smarty->setTemplateDir(self::__absPath($param['template_dir']));
     $smarty->setCompileDir(self::__absPath($param['compile_dir']));
     $smarty->setCompileCheck($param['compile_check'] != '0');
     $smarty->setConfigDir(self::__absPath($param['config_dir']));
     if (!empty($param['config_load'])) {
         $smarty->configLoad($param['config_load']);
     }
     $smarty->addPluginsDir(self::__absPath($param['plugins_dir']));
     $smarty->left_delimiter = $param['left_delimiter'];
     $smarty->right_delimiter = $param['right_delimiter'];
     if (isset($_COOKIE['FIS_DEBUG']) && $_COOKIE['FIS_DEBUG'] === 'YlwtSmt' && self::isInternalIp(Bd_Ip::getClientIp())) {
         return new Bd_TplFactory($smarty);
     }
     return $smarty;
 }