protected function _run() { $viewRedis = container()->getViewRedis(); $echo = func_get_arg(0); $file = $this->_viewFile; $isExpired = $this->expired(); if (false === $this->_compiled) { $isExpired = true; } if (false === $isExpired) { $file = $this->compiled(); } else { if (is_numeric($this->_cache)) { $cacheInst = new Cache(CACHE_PATH . DS); $hash = sha1($this->compiled() . $this->_cache . _serialize((array) $this)) . '.cache'; $cacheInst->forget($hash); } $file = $this->compiled($file); } if (null !== $this->_cache) { $isCached = isCached($file, $this->_cache, (array) $this); if (false === $isCached) { ob_start(); if (true !== $viewRedis) { include $file; } $content = ob_get_contents(); ob_end_clean(); if (true === $echo) { if (true !== $viewRedis) { echo cache($file, $content, $this->_cache, (array) $this); } } else { if (true !== $viewRedis) { return cache($file, $content, $this->_cache, (array) $this); } } } else { if (true !== $viewRedis) { $content = cache($file, null, $this->_cache, (array) $this); if (true === $echo) { echo $content; } else { return $content; } } } } else { if (true === $echo) { if (true !== $viewRedis) { include $file; } else { $this->compile($file); } } else { ob_start(); if (true !== $viewRedis) { include $file; } else { $this->compile($file); } $content = ob_get_contents(); ob_end_clean(); $hash = sha1($this->_viewFile); Utils::set($hash, $content); return $content; } } }
function _serialize($toSerialize) { $return = ''; $continue = true; if (is_array($toSerialize) || is_object($toSerialize)) { $continue = false; foreach ($toSerialize as $key => $value) { if ($value instanceof PDO) { $return .= serialize(array()); } else { $return .= _serialize($value); } } } if ($return == '' && true === $continue) { $return = serialize($toSerialize); } return $return; }
//是否有cookie,没有则设置,有则加入,超过5个自动删除 if (isset($_COOKIE['goods_history'])) { $history = _unserialize($_COOKIE['goods_history']); foreach ($history as $k => $v) { if ($v['goods_id'] != $goodsID) { continue; } else { array_splice($history, $k, 1); break; } } array_unshift($history, $goodsInfo); if (count($history) > 5) { array_pop($history); } setcookie('goods_history', _serialize($history), time() + 3600 * 24 * 7); } else { $history = array(); array_unshift($history, $goodsInfo); setcookie('goods_history', _serialize($history), time() + 3600 * 24 * 7); } if (isset($_SESSION['user_id'])) { $userid = $_SESSION['user_id']; $username = $_SESSION['username']; $email = $_SESSION['email']; } else { $userid = 0; $username = '******'; $email = ''; } include __ROOT__ . 'view/front/shangpin.html';