开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
forked from vb2005xu/sql.class.php
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
sql.class.php
/
migration
/
tpl.class.php
sql.class.php
/
migration
/
tpl.class.php
tpl.class.php 4.45 KB
一键复制 编辑 原始数据 按行查看 历史
vb2005xu 提交于 2015年01月15日 21:40 +08:00 . 新增迁移功能
<?php
/**
* @ sese 色色
* TplEngine 实现了一个简单的、使用 PHP 自身作为模版语言,
* 带有缓存功能的模版引擎
*/
class TplEngine
{
private $templateDir; //模板文件所在路径
private $cacheLifetime = 900; //缓存过期时间
private $enableCache = false; //指示是否使用 cache
private $cacheDir; //缓存文件保存位置
private $vars = array(); //模板变量
private $cacheState = array(); //保存各个缓存内容的缓存状态
/**
* @param array $params
*/
function __construct(array $params) {
$keys = array(
'templateDir', 'cacheDir', 'cacheLifeTime', 'enableCache',
);
foreach ($keys as $key) {
if (array_key_exists($key,$params))
$this->{$key} = $params[$key];
}
if (!is_dir($this->templateDir))
throw new Exception('templateDir 不是有效的目录');
if ($this->enableCache){
if (!is_dir($this->cacheDir))
throw new Exception('cacheDir 不是有效的目录');
}
}
/**
* 重设 模版变量
*
*/
function resetVars(){ $this->vars = array();}
/**
* 设置模板变量
*
* @param mixed $name 模板变量名称
* @param mixed $value 变量内容
*/
function assign($name, $value = null) {
if (is_array($name) && is_null($value)) {
$this->vars = array_merge($this->vars, $name);
} else {
$this->vars[$name] = $value;
}
}
/**
* 构造模板输出内容
*
* @param string $file 模板文件名
* @param string $cacheId 缓存 ID,如果指定该值则会使用该内容的缓存输出
*
* @return string
*/
function fetch($file, $cacheId = null) {
if ($this->enableCache) {
$cacheFile = $this->_getCacheFile($file, $cacheId);
if ($this->isCached($file, $cacheId)) {
return file_get_contents($cacheFile);
}
}
// 生成输出内容并缓存
extract($this->vars);
ob_start();
include($this->templateDir . '/' . $file);
$contents = ob_get_contents();
ob_end_clean();
if ($this->enableCache) {
// 缓存输出内容,并保存缓存状态
$this->cacheState[$cacheFile] = file_put_contents($cacheFile, $contents) > 0;
}
return $contents;
}
/**
* 显示指定模版的内容
*
* @param string $file 模板文件名
* @param string $cacheId 缓存 ID,如果指定该值则会使用该内容的缓存输出
*/
function display($file, $cacheId = null) {
echo $this->fetch($file, $cacheId);
}
/**
* 检查内容是否已经被缓存
*
* @param string $file 模板文件名
* @param string $cacheId 缓存 ID
*
* @return boolean
*/
function isCached($file, $cacheId = null) {
// 如果禁用缓存则返回 false
if (!$this->enableCache) { return false; }
// 如果缓存标志有效返回 true
$cacheFile = $this->_getCacheFile($file, $cacheId);
if (isset($this->cacheState[$cacheFile]) && $this->cacheState[$cacheFile]) {
return true;
}
// 检查缓存文件是否存在
if (!is_readable($cacheFile)) { return false; }
// 检查缓存文件是否已经过期
$mtime = filemtime($cacheFile);
if ($mtime == false) { return false; }
if (($mtime + $this->cacheLifetime) < time()) {
$this->cacheState[$cacheFile] = false;
@unlink($cacheFile);
return false;
}
$this->cacheState[$cacheFile] = true;
return true;
}
/**
* 清除指定的缓存
*
* @param string $file 模板资源名
* @param string $cacheId 缓存 ID
*/
function cleanCache($file, $cacheId = null) {
@unlink($this->_getCacheFile($file, $cacheId));
}
/**
* 清除所有缓存
*/
function cleanAllCache() {
foreach (glob($this->cacheDir . '/' . "*.html") as $filename) {
@unlink($filename);
}
}
/**
* 返回缓存文件名
*
* @param string $file
* @param string $cacheId
*
* @return string
*/
private function _getCacheFile($file, $cacheId) {
return $this->cacheDir . '/' . rawurlencode($file . '-' . $cacheId) . '.html';
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

最简单优雅的sql操作类库
暂无标签
GPL-3.0
使用 GPL-3.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/icando/sql.class.php.git
git@gitee.com:icando/sql.class.php.git
icando
sql.class.php
sql.class.php
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /