Exemple #1
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;
 }
Exemple #2
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;
 }
Exemple #3
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;
 }
Exemple #4
0
 public static function add($key = '', $var = '', $expire = 3600)
 {
     if (empty($var) || empty($key)) {
         return false;
     }
     $expire = intval($expire);
     if ($expire <= 0) {
         return false;
     }
     $expire = $expire > $_SERVER['REQUEST_TIME'] ? $expire : $expire + $_SERVER['REQUEST_TIME'];
     $content = $expire . self::$separator . serialize($var);
     if (ZOL_File::exists(self::$path)) {
         // add if caching was expired
         // no write yet
         if (false == ZOL_File::write($content, self::$path)) {
             return false;
         } else {
             return true;
         }
     } else {
         return false;
     }
 }
 /**
  * 设置文件缓存
  * @param array $cacheParam
  * @param mixed $content 内容
  * @param boolen $fileSyn 是否同步
  */
 public function set($cacheParam = null, $content = null, $fileSyn = false)
 {
     $this->processParam($cacheParam);
     //		var_dump($cacheParam);
     //		var_dump($this->_cacheParam);
     $this->_content = isset($content) ? $content : $this->_content;
     if (empty($this->_cachePath)) {
         return false;
     }
     //删除当前文件
     //		if (ZOL_File::exists($this->_cachePath) && empty($this->_content)) {
     //			$this->rm();
     //			return false;
     //		} elseif (empty($this->_content)) {
     //			return false;
     //		}
     if (is_object($this->_content)) {
         $this->_content = (array) $this->_content;
     }
     if (is_array($this->_content)) {
         #过滤空值
         $this->_content = self::arrayFilter($this->_content);
     }
     //var_dump($this->_content);
     #转换数据,以便保存
     $this->_convData($this->_content);
     $this->_endTime = microtime(true);
     #var_dump($this->_cachePath);
     if (ZOL_File::exists($this->_cachePath) || !empty($this->_content)) {
         //$sourceMd5 = md5($content);
         //$desMd5    = md5(ZOL_File::get($this->_cachePath));
         //if($sourceMd5 != $desMd5){#判断md5是否相同~~
         if ($fileSyn) {
             $this->fileSyn();
         }
         //}
         //			var_dump($this->_content, $this->_cachePath);
         ZOL_File::write($this->_content, $this->_cachePath);
         unset($content, $this->_content);
         return true;
     }
     return false;
 }