Ejemplo n.º 1
0
 public function save()
 {
     if (!self::$_entities) {
         throw new ZOL_Exception('the entities is empty!');
     }
     $content = '<?php return ' . var_export(SELF::$_entities, true) . '?>';
     return ZOL_File::write($content, self::$_entitiesListFile);
 }
Ejemplo n.º 2
0
 /**
  * 保存模块
  */
 private function saveCacheModules()
 {
     if (!$this->cacheModules) {
         throw new ZOL_Exception('The cacheModules is empty!');
     }
     $content = serialize($this->cacheModules);
     return ZOL_File::write($content, self::$cacheModulesListFile);
 }
Ejemplo n.º 3
0
 /**
  * 写入文件缓存
  */
 public static function set($cacheKey, $data)
 {
     if (!$data || !$cacheKey) {
         return false;
     }
     #获得缓存文件的地址
     $filePath = self::getCachePath($cacheKey);
     ZOL_File::write($data, $filePath);
     return false;
 }
Ejemplo n.º 4
0
 public function render(ZOL_Abstract_View $view)
 {
     $php = $this->_initEngine($view->data);
     if (!ZOL_File::exists($php->getTemplate())) {
         throw new ZOL_Exception('The template dose not exist or is not readable: ' . $php->getTemplate());
     }
     $variables = $php->getBody();
     if (!empty($variables)) {
         extract($variables);
     }
     ob_start();
     include $php->getTemplate();
     $content = ob_get_contents();
     ob_end_clean();
     return $content;
 }
Ejemplo n.º 5
0
 /**
  * 获取合并的前台JS CSS 链接
  * @param string|array $link
  * @param string $type 文件类型
  * @return string
  */
 public static function getMergeFrontendLink($file, $type)
 {
     $ver = (int) ZOL_File::get(PRODUCTION_ROOT . '/version.txt');
     if (IS_PRODUCTION) {
         #生产环境
         #$file = strtolower($file);
         $fileArr = array("http://s.zol-img.com.cn/d/" . APP_NAME . "/" . APP_NAME . "_{$file}.{$type}?v={$ver}");
         #$fileArr = array("http://s.zol-img.com.cn/product2011/{$type}/".APP_NAME."_{$file}.{$type}?v={$ver}");
     } else {
         #测试环境
         #读取配置文件
         $cssJsCfg = parse_ini_file(PRODUCTION_ROOT . "/Config/CssJs.ini", true);
         $files = $cssJsCfg[APP_NAME . "_" . $type][$file];
         if (!$files) {
             return '';
         }
         //add by lvj 2014-4-9 ZOL框架多人同时开发的支持 css和JS区分开
         if ($type == 'css' && defined('FE_TEST_CSS_USER') && defined('FE_TEST_CSS_URL')) {
             $files = str_replace(',', "," . str_replace('{USER}', FE_TEST_CSS_USER, FE_TEST_CSS_URL) . "/{$type}/", "/{$type}/" . $files);
         } elseif ($type == 'js' && defined('FE_TEST_JS_USER') && defined('FE_TEST_JS_URL')) {
             $files = str_replace(',', "," . str_replace('{USER}', FE_TEST_JS_USER, FE_TEST_JS_URL) . "/{$type}/", "/{$type}/" . $files);
         } else {
             #每个文件前面添加 /
             $files = str_replace(',', ",/{$type}/", "/{$type}/" . $files);
         }
         $fileArr = explode(",", $files);
     }
     $html = '';
     if ($fileArr) {
         foreach ($fileArr as $url) {
             switch (strtolower($type)) {
                 case 'css':
                     $html .= '<link href="' . $url . '" rel="stylesheet" type="text/css" />';
                     break;
                 case 'js':
                     $html .= '<script type="text/javascript" src="' . $url . '" charset="gbk"></script>';
                     break;
                 default:
                     return false;
             }
             $html .= "\r\n";
         }
     }
     return $html;
 }
Ejemplo n.º 6
0
 /**
  * 获取
  *
  * @param mixed $key 配置地址
  * @param mixed $arrKeyName 配置子键,可多维,用.号分隔
  * @param enum $type PHP|INI|EVAL
  * @return array|false
  */
 public static function get($key, $arrKeyName = '', $type = 'PHP')
 {
     $fileExt = array('ini' => 'ini', 'php' => 'php', 'eval' => 'php');
     $path = ZOL_API_ROOT . '/Config/' . str_replace('_', '/', $key) . '.' . $fileExt[strtolower($type)];
     if (isset(self::$_cache[$path])) {
         $config = self::$_cache[$path];
     } else {
         if (!ZOL_File::exists($path)) {
             self::$_cache[$path] = false;
             return false;
         }
         $type = strtoupper($type);
         switch ($type) {
             case 'INI':
                 $config = parse_ini_file($path);
                 break;
             case 'EVAL':
                 #config中可以有变量,这样可以将变量传入到config中
                 if (is_array($arrKeyName)) {
                     extract($arrKeyName);
                 }
                 $config = (include $path);
                 break;
             default:
             case 'PHP':
                 $config = (include $path);
                 break;
         }
         self::$_cache[$path] = $config;
     }
     if ($arrKeyName && $type != 'EVAL') {
         if (strpos('.', $arrKeyName)) {
             $keyArr = explode('.', $arrKeyName);
             foreach ($keyArr as $key) {
                 if (!$config) {
                     break;
                 }
                 $config = empty($config[$key]) ? false : $config[$key];
             }
         } else {
             $config = empty($config[$arrKeyName]) ? false : $config[$arrKeyName];
         }
     }
     return $config;
 }
Ejemplo n.º 7
0
 /**
  * »ñÈ¡
  *
  * @param mixed $key ÅäÖõØÖ·
  * @param mixed $arrKeyName ÅäÖÃ×Ó¼ü£¬¿É¶àά£¬ÓÃ.ºÅ·Ö¸ô
  * @param enum $type PHP|INI
  * @return array|false
  */
 public static function get($key, $arrKeyName = '', $type = 'PHP')
 {
     if (!defined('PRODUCTION_CONFIG_PATH')) {
         define('PRODUCTION_CONFIG_PATH', PRODUCTION_ROOT . '/Config');
     }
     $path = PRODUCTION_CONFIG_PATH . '/' . str_replace('_', '/', $key) . '.' . strtolower($type);
     if (isset(self::$_cache[$path])) {
         $config = self::$_cache[$path];
     } else {
         if (!ZOL_File::exists($path)) {
             self::$_cache[$path] = false;
             return false;
         }
         switch ($type) {
             case 'INI':
                 $config = parse_ini_file($path);
                 break;
             default:
             case 'PHP':
                 $config = (include $path);
                 break;
         }
         self::$_cache[$path] = $config;
     }
     if ($arrKeyName) {
         if (strpos('.', $arrKeyName)) {
             $keyArr = explode('.', $arrKeyName);
             foreach ($keyArr as $key) {
                 if (!$config) {
                     break;
                 }
                 $config = empty($config[$key]) ? false : $config[$key];
             }
         } else {
             $config = empty($config[$arrKeyName]) ? false : $config[$arrKeyName];
         }
     }
     return $config;
 }
Ejemplo n.º 8
0
 public static function write($message, $type, $hasMark = true)
 {
     if (empty($message)) {
         trigger_error('$message dose not empty! ');
         return false;
     }
     if (empty($type)) {
         trigger_error('$type dose not empty! ');
         return false;
     }
     if (!isset(self::$type[$type])) {
         trigger_error('Unknow log type: ' . $type);
         return false;
     }
     $var = defined('ZOL_API_LOG') ? ZOL_API_LOG : SYSTEM_VAR;
     $path = $var . '/log/' . self::$type[$type] . '/' . date('Y/m/d') . '.log';
     if ($hasMark) {
         $mark = "\n\n===========================================================================\n";
         $mark .= 'time:' . date('Y/m/d H:i:s') . "\n";
         $message = $mark . $message;
     }
     return ZOL_File::write($message, $path, FILE_APPEND | LOCK_EX);
 }
Ejemplo n.º 9
0
 public static function get($file, $intoAnArray = false)
 {
     self::$_file = self::exists($file);
     if (!self::$_file) {
         //throw new ZOL_Exception('File does not exist or is not readable: '.$file);
         //trigger_error('File does not exist or is not readable: ' . $file);
         return false;
     }
     unset($file);
     if (false == $intoAnArray) {
         return file_get_contents(self::$_file);
     } else {
         return file(self::$_file);
     }
 }
Ejemplo n.º 10
0
 public function buildStaticPage(array $data, $template, $filePath)
 {
     if (empty($data)) {
         trigger_error('$data dose not empty!');
         return false;
     }
     if (empty($template)) {
         trigger_error('$template dose not empty!');
         return false;
     }
     if (empty($filePath)) {
         trigger_error('$filePath dose not empty!');
         return false;
     }
     $output = new ZOL_Response();
     $output->add($data);
     $output->template = $template;
     $view = new ZOL_View_Simple($output);
     ZOL_File::write($view->render(), $filePath);
     return false;
 }
Ejemplo n.º 11
0
 public static function lock($key)
 {
     $cacheFile = self::path($key);
     $cacheDir = dirname($cacheFile);
     if (!is_dir($cacheDir)) {
         if (!ZOL_File::mkdir($cacheDir, 0755, true)) {
             // make sure the failure isn't because of a concurency issue
             if (!is_dir($cacheDir)) {
                 throw new ZOL_Exception("Could not create cache directory");
             }
         }
     }
     @touch($cacheFile . '.lock');
 }
Ejemplo n.º 12
0
 public static function setCache($html = null, $url = null)
 {
     $key = self::$_cacheKey;
     $html = is_null($html) ? self::$_html : $html;
     if (!$html) {
         return false;
     }
     $html = gzdeflate($html, 9);
     return ZOL_File::write($html, $key);
 }
Ejemplo n.º 13
0
 /**
  * 创建缩略图
  * 
  * @param string $path 原图
  * @param string $toPath 生成后的图
  * @param string $size 图片尺寸
  */
 public function makeThumb($path, $toPath, $size)
 {
     $size = strtolower($size);
     $toDir = dirname($toPath);
     is_dir($toDir) || ZOL_File::mkdir($toDir);
     system("convert -geometry {$size} {$path} {$toPath} ");
     return $this;
 }
Ejemplo n.º 14
0
 /**
  * 删除文件缓存
  */
 public function rm($cacheParam = null)
 {
     $this->processParam($cacheParam);
     if (empty($this->_cachePath) || !file_exists($this->_cachePath)) {
         return false;
     }
     return ZOL_File::rm($this->_cachePath);
 }