Ejemplo n.º 1
0
 /**
  * 输出js/css连接
  *
  * @param $res_link
  * @param bool $make_link
  * @return null|string
  */
 function outputResLink($res_link, $make_link = true)
 {
     $t = Helper::getExt($res_link);
     switch (strtolower($t)) {
         case 'js':
             $tpl = '<script type="text/javascript" src="%s"></script>';
             break;
         case 'css':
             $tpl = '<link rel="stylesheet" type="text/css" href="%s"/>';
             break;
         default:
             $tpl = null;
     }
     if (null !== $tpl) {
         if ($make_link) {
             $res_link = $this->res($res_link);
         }
         return sprintf("{$tpl}\n", $res_link);
     }
     return null;
 }
Ejemplo n.º 2
0
 /**
  * 读取指定的单一文件
  *
  * @param string $file Loader::parseFileRealPath()
  * @param bool $require_file 是否返回文件 等于false时,返回文件文本内容
  * @return mixed
  * @throws CoreException
  */
 public static function read($file, $require_file = true)
 {
     if (is_file($file)) {
         $file_path = $file;
     } else {
         $file_path = Loader::getFilePath($file);
     }
     $read_file_flag = (int) $require_file;
     if (isset(self::$loaded[$file_path][$read_file_flag])) {
         return self::$loaded[$file_path][$read_file_flag];
     }
     if (is_readable($file_path)) {
         if (false === $require_file) {
             $file_content = file_get_contents($file_path);
             self::$loaded[$file_path][$read_file_flag] = $file_content;
             return $file_content;
         }
         $ext = Helper::getExt($file_path);
         switch ($ext) {
             case 'php':
                 $data = (require $file_path);
                 self::$loaded[$file_path][$read_file_flag] = $data;
                 break;
             case 'json':
                 $data = json_decode(file_get_contents($file_path), true);
                 self::$loaded[$file_path][$read_file_flag] = $data;
                 break;
             case 'ini':
                 $data = parse_ini_file($file_path, true);
                 self::$loaded[$file_path][$read_file_flag] = $data;
                 break;
             default:
                 throw new CoreException('不支持的解析格式');
         }
         return $data;
     } else {
         throw new CoreException("读取文件失败:{$file}");
     }
 }