1、更换编辑器
2、seo优化功能 3、表单的bug
This commit is contained in:
390
core/helper.php
390
core/helper.php
@@ -27,29 +27,29 @@ use think\Session;
|
||||
use think\Url;
|
||||
use think\View;
|
||||
|
||||
/**
|
||||
* 快速导入Traits PHP5.5以上无需调用
|
||||
* @param string $class trait库
|
||||
* @param string $ext 类库后缀
|
||||
* @return boolean
|
||||
*/
|
||||
if (!function_exists('load_trait')) {
|
||||
/**
|
||||
* 快速导入Traits PHP5.5以上无需调用
|
||||
* @param string $class trait库
|
||||
* @param string $ext 类库后缀
|
||||
* @return boolean
|
||||
*/
|
||||
function load_trait($class, $ext = EXT)
|
||||
{
|
||||
return Loader::import($class, TRAIT_PATH, $ext);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 抛出异常处理
|
||||
*
|
||||
* @param string $msg 异常消息
|
||||
* @param integer $code 异常代码 默认为0
|
||||
* @param string $exception 异常类
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
if (!function_exists('exception')) {
|
||||
/**
|
||||
* 抛出异常处理
|
||||
*
|
||||
* @param string $msg 异常消息
|
||||
* @param integer $code 异常代码 默认为0
|
||||
* @param string $exception 异常类
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
function exception($msg, $code = 0, $exception = '')
|
||||
{
|
||||
$e = $exception ?: '\think\Exception';
|
||||
@@ -57,14 +57,14 @@ if (!function_exists('exception')) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录时间(微秒)和内存使用情况
|
||||
* @param string $start 开始标签
|
||||
* @param string $end 结束标签
|
||||
* @param integer|string $dec 小数位 如果是m 表示统计内存占用
|
||||
* @return mixed
|
||||
*/
|
||||
if (!function_exists('debug')) {
|
||||
/**
|
||||
* 记录时间(微秒)和内存使用情况
|
||||
* @param string $start 开始标签
|
||||
* @param string $end 结束标签
|
||||
* @param integer|string $dec 小数位 如果是m 表示统计内存占用
|
||||
* @return mixed
|
||||
*/
|
||||
function debug($start, $end = '', $dec = 6)
|
||||
{
|
||||
if ('' == $end) {
|
||||
@@ -75,28 +75,28 @@ if (!function_exists('debug')) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取语言变量值
|
||||
* @param string $name 语言变量名
|
||||
* @param array $vars 动态变量值
|
||||
* @param string $lang 语言
|
||||
* @return mixed
|
||||
*/
|
||||
if (!function_exists('lang')) {
|
||||
/**
|
||||
* 获取语言变量值
|
||||
* @param string $name 语言变量名
|
||||
* @param array $vars 动态变量值
|
||||
* @param string $lang 语言
|
||||
* @return mixed
|
||||
*/
|
||||
function lang($name, $vars = [], $lang = '')
|
||||
{
|
||||
return Lang::get($name, $vars, $lang);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取和设置配置参数
|
||||
* @param string|array $name 参数名
|
||||
* @param mixed $value 参数值
|
||||
* @param string $range 作用域
|
||||
* @return mixed
|
||||
*/
|
||||
if (!function_exists('config')) {
|
||||
/**
|
||||
* 获取和设置配置参数
|
||||
* @param string|array $name 参数名
|
||||
* @param mixed $value 参数值
|
||||
* @param string $range 作用域
|
||||
* @return mixed
|
||||
*/
|
||||
function config($name = '', $value = null, $range = '')
|
||||
{
|
||||
if (is_null($value) && is_string($name)) {
|
||||
@@ -107,14 +107,14 @@ if (!function_exists('config')) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取输入数据 支持默认值和过滤
|
||||
* @param string $key 获取的变量名
|
||||
* @param mixed $default 默认值
|
||||
* @param string $filter 过滤方法
|
||||
* @return mixed
|
||||
*/
|
||||
if (!function_exists('input')) {
|
||||
/**
|
||||
* 获取输入数据 支持默认值和过滤
|
||||
* @param string $key 获取的变量名
|
||||
* @param mixed $default 默认值
|
||||
* @param string $filter 过滤方法
|
||||
* @return mixed
|
||||
*/
|
||||
function input($key, $default = null, $filter = null)
|
||||
{
|
||||
if (0 === strpos($key, '?')) {
|
||||
@@ -141,153 +141,153 @@ if (!function_exists('input')) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染输出Widget
|
||||
* @param string $name Widget名称
|
||||
* @param array $data 传人的参数
|
||||
* @return mixed
|
||||
*/
|
||||
if (!function_exists('widget')) {
|
||||
/**
|
||||
* 渲染输出Widget
|
||||
* @param string $name Widget名称
|
||||
* @param array $data 传人的参数
|
||||
* @return mixed
|
||||
*/
|
||||
function widget($name, $data = [])
|
||||
{
|
||||
return Loader::action($name, $data, 'widget');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 实例化Model
|
||||
* @param string $name Model名称
|
||||
* @param string $layer 业务层名称
|
||||
* @param bool $appendSuffix 是否添加类名后缀
|
||||
* @return \think\Model
|
||||
*/
|
||||
if (!function_exists('model')) {
|
||||
/**
|
||||
* 实例化Model
|
||||
* @param string $name Model名称
|
||||
* @param string $layer 业务层名称
|
||||
* @param bool $appendSuffix 是否添加类名后缀
|
||||
* @return \think\Model
|
||||
*/
|
||||
function model($name = '', $layer = 'model', $appendSuffix = false)
|
||||
{
|
||||
return Loader::model($name, $layer, $appendSuffix);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 实例化验证器
|
||||
* @param string $name 验证器名称
|
||||
* @param string $layer 业务层名称
|
||||
* @param bool $appendSuffix 是否添加类名后缀
|
||||
* @return \think\Validate
|
||||
*/
|
||||
if (!function_exists('validate')) {
|
||||
/**
|
||||
* 实例化验证器
|
||||
* @param string $name 验证器名称
|
||||
* @param string $layer 业务层名称
|
||||
* @param bool $appendSuffix 是否添加类名后缀
|
||||
* @return \think\Validate
|
||||
*/
|
||||
function validate($name = '', $layer = 'validate', $appendSuffix = false)
|
||||
{
|
||||
return Loader::validate($name, $layer, $appendSuffix);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 实例化数据库类
|
||||
* @param string $name 操作的数据表名称(不含前缀)
|
||||
* @param array|string $config 数据库配置参数
|
||||
* @return \think\db\Query
|
||||
*/
|
||||
if (!function_exists('db')) {
|
||||
/**
|
||||
* 实例化数据库类
|
||||
* @param string $name 操作的数据表名称(不含前缀)
|
||||
* @param array|string $config 数据库配置参数
|
||||
* @return \think\db\Query
|
||||
*/
|
||||
function db($name = '', $config = [])
|
||||
{
|
||||
return Db::connect($config)->name($name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 实例化控制器 格式:[模块/]控制器
|
||||
* @param string $name 资源地址
|
||||
* @param string $layer 控制层名称
|
||||
* @param bool $appendSuffix 是否添加类名后缀
|
||||
* @return \think\Controller
|
||||
*/
|
||||
if (!function_exists('controller')) {
|
||||
/**
|
||||
* 实例化控制器 格式:[模块/]控制器
|
||||
* @param string $name 资源地址
|
||||
* @param string $layer 控制层名称
|
||||
* @param bool $appendSuffix 是否添加类名后缀
|
||||
* @return \think\Controller
|
||||
*/
|
||||
function controller($name, $layer = 'controller', $appendSuffix = false)
|
||||
{
|
||||
return Loader::controller($name, $layer, $appendSuffix);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用模块的操作方法 参数格式 [模块/控制器/]操作
|
||||
* @param string $url 调用地址
|
||||
* @param string|array $vars 调用参数 支持字符串和数组
|
||||
* @param string $layer 要调用的控制层名称
|
||||
* @param bool $appendSuffix 是否添加类名后缀
|
||||
* @return mixed
|
||||
*/
|
||||
if (!function_exists('action')) {
|
||||
/**
|
||||
* 调用模块的操作方法 参数格式 [模块/控制器/]操作
|
||||
* @param string $url 调用地址
|
||||
* @param string|array $vars 调用参数 支持字符串和数组
|
||||
* @param string $layer 要调用的控制层名称
|
||||
* @param bool $appendSuffix 是否添加类名后缀
|
||||
* @return mixed
|
||||
*/
|
||||
function action($url, $vars = [], $layer = 'controller', $appendSuffix = false)
|
||||
{
|
||||
return Loader::action($url, $vars, $layer, $appendSuffix);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入所需的类库 同java的Import 本函数有缓存功能
|
||||
* @param string $class 类库命名空间字符串
|
||||
* @param string $baseUrl 起始路径
|
||||
* @param string $ext 导入的文件扩展名
|
||||
* @return boolean
|
||||
*/
|
||||
if (!function_exists('import')) {
|
||||
/**
|
||||
* 导入所需的类库 同java的Import 本函数有缓存功能
|
||||
* @param string $class 类库命名空间字符串
|
||||
* @param string $baseUrl 起始路径
|
||||
* @param string $ext 导入的文件扩展名
|
||||
* @return boolean
|
||||
*/
|
||||
function import($class, $baseUrl = '', $ext = EXT)
|
||||
{
|
||||
return Loader::import($class, $baseUrl, $ext);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速导入第三方框架类库 所有第三方框架的类库文件统一放到 系统的Vendor目录下面
|
||||
* @param string $class 类库
|
||||
* @param string $ext 类库后缀
|
||||
* @return boolean
|
||||
*/
|
||||
if (!function_exists('vendor')) {
|
||||
/**
|
||||
* 快速导入第三方框架类库 所有第三方框架的类库文件统一放到 系统的Vendor目录下面
|
||||
* @param string $class 类库
|
||||
* @param string $ext 类库后缀
|
||||
* @return boolean
|
||||
*/
|
||||
function vendor($class, $ext = EXT)
|
||||
{
|
||||
return Loader::import($class, VENDOR_PATH, $ext);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 浏览器友好的变量输出
|
||||
* @param mixed $var 变量
|
||||
* @param boolean $echo 是否输出 默认为true 如果为false 则返回输出字符串
|
||||
* @param string $label 标签 默认为空
|
||||
* @return void|string
|
||||
*/
|
||||
if (!function_exists('dump')) {
|
||||
/**
|
||||
* 浏览器友好的变量输出
|
||||
* @param mixed $var 变量
|
||||
* @param boolean $echo 是否输出 默认为true 如果为false 则返回输出字符串
|
||||
* @param string $label 标签 默认为空
|
||||
* @return void|string
|
||||
*/
|
||||
function dump($var, $echo = true, $label = null)
|
||||
{
|
||||
return Debug::dump($var, $echo, $label);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Url生成
|
||||
* @param string $url 路由地址
|
||||
* @param string|array $value 变量
|
||||
* @param bool|string $suffix 前缀
|
||||
* @param bool|string $domain 域名
|
||||
* @return string
|
||||
*/
|
||||
if (!function_exists('url')) {
|
||||
/**
|
||||
* Url生成
|
||||
* @param string $url 路由地址
|
||||
* @param string|array $value 变量
|
||||
* @param bool|string $suffix 前缀
|
||||
* @param bool|string $domain 域名
|
||||
* @return string
|
||||
*/
|
||||
function url($url = '', $vars = '', $suffix = true, $domain = false)
|
||||
{
|
||||
return Url::build($url, $vars, $suffix, $domain);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Session管理
|
||||
* @param string|array $name session名称,如果为数组表示进行session设置
|
||||
* @param mixed $value session值
|
||||
* @param string $prefix 前缀
|
||||
* @return mixed
|
||||
*/
|
||||
if (!function_exists('session')) {
|
||||
/**
|
||||
* Session管理
|
||||
* @param string|array $name session名称,如果为数组表示进行session设置
|
||||
* @param mixed $value session值
|
||||
* @param string $prefix 前缀
|
||||
* @return mixed
|
||||
*/
|
||||
function session($name, $value = '', $prefix = null)
|
||||
{
|
||||
if (is_array($name)) {
|
||||
@@ -309,14 +309,14 @@ if (!function_exists('session')) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cookie管理
|
||||
* @param string|array $name cookie名称,如果为数组表示进行cookie设置
|
||||
* @param mixed $value cookie值
|
||||
* @param mixed $option 参数
|
||||
* @return mixed
|
||||
*/
|
||||
if (!function_exists('cookie')) {
|
||||
/**
|
||||
* Cookie管理
|
||||
* @param string|array $name cookie名称,如果为数组表示进行cookie设置
|
||||
* @param mixed $value cookie值
|
||||
* @param mixed $option 参数
|
||||
* @return mixed
|
||||
*/
|
||||
function cookie($name, $value = '', $option = null)
|
||||
{
|
||||
if (is_array($name)) {
|
||||
@@ -338,14 +338,14 @@ if (!function_exists('cookie')) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存管理
|
||||
* @param mixed $name 缓存名称,如果为数组表示进行缓存设置
|
||||
* @param mixed $value 缓存值
|
||||
* @param mixed $options 缓存参数
|
||||
* @return mixed
|
||||
*/
|
||||
if (!function_exists('cache')) {
|
||||
/**
|
||||
* 缓存管理
|
||||
* @param mixed $name 缓存名称,如果为数组表示进行缓存设置
|
||||
* @param mixed $value 缓存值
|
||||
* @param mixed $options 缓存参数
|
||||
* @return mixed
|
||||
*/
|
||||
function cache($name, $value = '', $options = null)
|
||||
{
|
||||
if (is_array($options)) {
|
||||
@@ -373,13 +373,13 @@ if (!function_exists('cache')) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录日志信息
|
||||
* @param mixed $log log信息 支持字符串和数组
|
||||
* @param string $level 日志级别
|
||||
* @return void|array
|
||||
*/
|
||||
if (!function_exists('trace')) {
|
||||
/**
|
||||
* 记录日志信息
|
||||
* @param mixed $log log信息 支持字符串和数组
|
||||
* @param string $level 日志级别
|
||||
* @return void|array
|
||||
*/
|
||||
function trace($log = '[think]', $level = 'log')
|
||||
{
|
||||
if ('[think]' === $log) {
|
||||
@@ -390,99 +390,99 @@ if (!function_exists('trace')) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前Request对象实例
|
||||
* @return Request
|
||||
*/
|
||||
if (!function_exists('request')) {
|
||||
/**
|
||||
* 获取当前Request对象实例
|
||||
* @return Request
|
||||
*/
|
||||
function request()
|
||||
{
|
||||
return Request::instance();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建普通 Response 对象实例
|
||||
* @param mixed $data 输出数据
|
||||
* @param int|string $code 状态码
|
||||
* @param array $header 头信息
|
||||
* @param string $type
|
||||
* @return Response
|
||||
*/
|
||||
if (!function_exists('response')) {
|
||||
/**
|
||||
* 创建普通 Response 对象实例
|
||||
* @param mixed $data 输出数据
|
||||
* @param int|string $code 状态码
|
||||
* @param array $header 头信息
|
||||
* @param string $type
|
||||
* @return Response
|
||||
*/
|
||||
function response($data = [], $code = 200, $header = [], $type = 'html')
|
||||
{
|
||||
return Response::create($data, $type, $code, $header);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染模板输出
|
||||
* @param string $template 模板文件
|
||||
* @param array $vars 模板变量
|
||||
* @param integer $code 状态码
|
||||
* @return \think\response\View
|
||||
*/
|
||||
if (!function_exists('view')) {
|
||||
/**
|
||||
* 渲染模板输出
|
||||
* @param string $template 模板文件
|
||||
* @param array $vars 模板变量
|
||||
* @param integer $code 状态码
|
||||
* @return \think\response\View
|
||||
*/
|
||||
function view($template = '', $vars = [], $code = 200)
|
||||
{
|
||||
return Response::create($template, 'view', $code)->vars($vars);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取\think\response\Json对象实例
|
||||
* @param mixed $data 返回的数据
|
||||
* @param integer $code 状态码
|
||||
* @param array $header 头部
|
||||
* @param array $options 参数
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
if (!function_exists('json')) {
|
||||
/**
|
||||
* 获取\think\response\Json对象实例
|
||||
* @param mixed $data 返回的数据
|
||||
* @param integer $code 状态码
|
||||
* @param array $header 头部
|
||||
* @param array $options 参数
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
function json($data = [], $code = 200, $header = [], $options = [])
|
||||
{
|
||||
return Response::create($data, 'json', $code, $header, $options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取\think\response\Jsonp对象实例
|
||||
* @param mixed $data 返回的数据
|
||||
* @param integer $code 状态码
|
||||
* @param array $header 头部
|
||||
* @param array $options 参数
|
||||
* @return \think\response\Jsonp
|
||||
*/
|
||||
if (!function_exists('jsonp')) {
|
||||
/**
|
||||
* 获取\think\response\Jsonp对象实例
|
||||
* @param mixed $data 返回的数据
|
||||
* @param integer $code 状态码
|
||||
* @param array $header 头部
|
||||
* @param array $options 参数
|
||||
* @return \think\response\Jsonp
|
||||
*/
|
||||
function jsonp($data = [], $code = 200, $header = [], $options = [])
|
||||
{
|
||||
return Response::create($data, 'jsonp', $code, $header, $options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取\think\response\Xml对象实例
|
||||
* @param mixed $data 返回的数据
|
||||
* @param integer $code 状态码
|
||||
* @param array $header 头部
|
||||
* @param array $options 参数
|
||||
* @return \think\response\Xml
|
||||
*/
|
||||
if (!function_exists('xml')) {
|
||||
/**
|
||||
* 获取\think\response\Xml对象实例
|
||||
* @param mixed $data 返回的数据
|
||||
* @param integer $code 状态码
|
||||
* @param array $header 头部
|
||||
* @param array $options 参数
|
||||
* @return \think\response\Xml
|
||||
*/
|
||||
function xml($data = [], $code = 200, $header = [], $options = [])
|
||||
{
|
||||
return Response::create($data, 'xml', $code, $header, $options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取\think\response\Redirect对象实例
|
||||
* @param mixed $url 重定向地址 支持Url::build方法的地址
|
||||
* @param array|integer $params 额外参数
|
||||
* @param integer $code 状态码
|
||||
* @return \think\response\Redirect
|
||||
*/
|
||||
if (!function_exists('redirect')) {
|
||||
/**
|
||||
* 获取\think\response\Redirect对象实例
|
||||
* @param mixed $url 重定向地址 支持Url::build方法的地址
|
||||
* @param array|integer $params 额外参数
|
||||
* @param integer $code 状态码
|
||||
* @return \think\response\Redirect
|
||||
*/
|
||||
function redirect($url = [], $params = [], $code = 302)
|
||||
{
|
||||
if (is_integer($params)) {
|
||||
@@ -493,13 +493,13 @@ if (!function_exists('redirect')) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 抛出HTTP异常
|
||||
* @param integer $code 状态码
|
||||
* @param string $message 错误信息
|
||||
* @param array $header 参数
|
||||
*/
|
||||
if (!function_exists('abort')) {
|
||||
/**
|
||||
* 抛出HTTP异常
|
||||
* @param integer $code 状态码
|
||||
* @param string $message 错误信息
|
||||
* @param array $header 参数
|
||||
*/
|
||||
function abort($code, $message = null, $header = [])
|
||||
{
|
||||
throw new \think\exception\HttpException($code, $message, null, $header);
|
||||
|
||||
@@ -57,7 +57,7 @@ class Build
|
||||
foreach ($list as $dir) {
|
||||
if (!is_dir(APP_PATH . $dir)) {
|
||||
// 创建目录
|
||||
mkdir(APP_PATH . $dir, 0777, true);
|
||||
mkdir(APP_PATH . $dir, 0644, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ class Build
|
||||
foreach ($list as $file) {
|
||||
if (!is_dir(APP_PATH . dirname($file))) {
|
||||
// 创建目录
|
||||
mkdir(APP_PATH . dirname($file), 0777, true);
|
||||
mkdir(APP_PATH . dirname($file), 0644, true);
|
||||
}
|
||||
if (!is_file(APP_PATH . $file)) {
|
||||
file_put_contents(APP_PATH . $file, 'php' == pathinfo($file, PATHINFO_EXTENSION) ? "<?php\n" : '');
|
||||
@@ -118,7 +118,7 @@ class Build
|
||||
foreach ($file as $dir) {
|
||||
if (!is_dir($modulePath . $dir)) {
|
||||
// 创建目录
|
||||
mkdir($modulePath . $dir, 0777, true);
|
||||
mkdir($modulePath . $dir, 0644, true);
|
||||
}
|
||||
}
|
||||
} elseif ('__file__' == $path) {
|
||||
@@ -146,7 +146,7 @@ class Build
|
||||
$filename = $modulePath . $path . DS . $val . '.html';
|
||||
if (!is_dir(dirname($filename))) {
|
||||
// 创建目录
|
||||
mkdir(dirname($filename), 0777, true);
|
||||
mkdir(dirname($filename), 0644, true);
|
||||
}
|
||||
$content = '';
|
||||
break;
|
||||
@@ -178,7 +178,7 @@ class Build
|
||||
$content = file_get_contents(THINK_PATH . 'tpl' . DS . 'default_index.tpl');
|
||||
$content = str_replace(['{$app}', '{$module}', '{layer}', '{$suffix}'], [$namespace, $module ? $module . '\\' : '', 'controller', $suffix ? 'Controller' : ''], $content);
|
||||
if (!is_dir(dirname($filename))) {
|
||||
mkdir(dirname($filename), 0777, true);
|
||||
mkdir(dirname($filename), 0644, true);
|
||||
}
|
||||
file_put_contents($filename, $content);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ class File extends SplFileObject
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mkdir($path, 0777, true)) {
|
||||
if (mkdir($path, 0644, true)) {
|
||||
return true;
|
||||
} else {
|
||||
$this->error = "目录 {$path} 创建失败!";
|
||||
|
||||
@@ -623,7 +623,7 @@ class Request
|
||||
// 当前请求参数和URL地址中的参数合并
|
||||
$this->param = array_merge($this->route(false), $this->get(false), $vars);
|
||||
}
|
||||
return false === $name ? $this->param : $this->input($this->param, $name, $default, $filter);
|
||||
return $this->input($this->param, $name, $default, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -639,7 +639,7 @@ class Request
|
||||
if (is_array($name)) {
|
||||
return $this->route = array_merge($this->route, $name);
|
||||
}
|
||||
return false === $name ? $this->route : $this->input($this->route, $name, $default, $filter);
|
||||
return $this->input($this->route, $name, $default, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -657,7 +657,7 @@ class Request
|
||||
} elseif (empty($this->get)) {
|
||||
$this->get = $_GET;
|
||||
}
|
||||
return false === $name ? $this->get : $this->input($this->get, $name, $default, $filter);
|
||||
return $this->input($this->get, $name, $default, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -675,7 +675,7 @@ class Request
|
||||
} elseif (empty($this->post)) {
|
||||
$this->post = $_POST;
|
||||
}
|
||||
return false === $name ? $this->post : $this->input($this->post, $name, $default, $filter);
|
||||
return $this->input($this->post, $name, $default, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -692,9 +692,14 @@ class Request
|
||||
return $this->put = is_null($this->put) ? $name : array_merge($this->put, $name);
|
||||
}
|
||||
if (is_null($this->put)) {
|
||||
parse_str(file_get_contents('php://input'), $this->put);
|
||||
$content = file_get_contents('php://input');
|
||||
if (strpos($content, '":')) {
|
||||
$this->put = json_decode($content, true);
|
||||
} else {
|
||||
parse_str($content, $this->put);
|
||||
}
|
||||
}
|
||||
return false === $name ? $this->put : $this->input($this->put, $name, $default, $filter);
|
||||
return $this->input($this->put, $name, $default, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -713,7 +718,7 @@ class Request
|
||||
if (is_null($this->delete)) {
|
||||
parse_str(file_get_contents('php://input'), $this->delete);
|
||||
}
|
||||
return false === $name ? $this->delete : $this->input($this->delete, $name, $default, $filter);
|
||||
return $this->input($this->delete, $name, $default, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -730,7 +735,7 @@ class Request
|
||||
} elseif (empty($this->request)) {
|
||||
$this->request = $_REQUEST;
|
||||
}
|
||||
return false === $name ? $this->request : $this->input($this->request ?: $_REQUEST, $name, $default, $filter);
|
||||
return $this->input($this->request ?: $_REQUEST, $name, $default, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -748,7 +753,7 @@ class Request
|
||||
} elseif (empty($this->session)) {
|
||||
$this->session = Session::get();
|
||||
}
|
||||
return false === $name ? $this->session : $this->input($this->session, $name, $default, $filter);
|
||||
return $this->input($this->session, $name, $default, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -766,7 +771,7 @@ class Request
|
||||
} elseif (empty($this->cookie)) {
|
||||
$this->cookie = $_COOKIE;
|
||||
}
|
||||
return false === $name ? $this->cookie : $this->input($this->cookie, $name, $default, $filter);
|
||||
return $this->input($this->cookie, $name, $default, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -784,7 +789,7 @@ class Request
|
||||
} elseif (empty($this->server)) {
|
||||
$this->server = $_SERVER;
|
||||
}
|
||||
return false === $name ? $this->server : $this->input($this->server, $name, $default, $filter);
|
||||
return $this->input($this->server, false === $name ? false : strtoupper($name), $default, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -804,44 +809,43 @@ class Request
|
||||
if (!empty($files)) {
|
||||
// 处理上传文件
|
||||
$array = [];
|
||||
$n = 0;
|
||||
foreach ($files as $key => $file) {
|
||||
if (is_array($file['name'])) {
|
||||
$item = [];
|
||||
$keys = array_keys($file);
|
||||
$count = count($file['name']);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$array[$n]['key'] = $key;
|
||||
foreach ($keys as $_key) {
|
||||
$array[$n][$_key] = $file[$_key][$i];
|
||||
}
|
||||
$n++;
|
||||
}
|
||||
} else {
|
||||
$array = $files;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ('' === $name) {
|
||||
// 获取全部文件
|
||||
$item = [];
|
||||
foreach ($array as $key => $val) {
|
||||
if ($val instanceof File) {
|
||||
$item[$key] = $val;
|
||||
} else {
|
||||
if (empty($val['tmp_name'])) {
|
||||
if (empty($file['tmp_name'][$i])) {
|
||||
continue;
|
||||
}
|
||||
$item[$key] = (new File($val['tmp_name']))->setUploadInfo($val);
|
||||
$temp['key'] = $key;
|
||||
foreach ($keys as $_key) {
|
||||
$temp[$_key] = $file[$_key][$i];
|
||||
}
|
||||
$item[] = (new File($temp['tmp_name']))->setUploadInfo($temp);
|
||||
}
|
||||
$array[$key] = $item;
|
||||
} else {
|
||||
if ($file instanceof File) {
|
||||
$array[$key] = $file;
|
||||
} else {
|
||||
if (empty($file['tmp_name'])) {
|
||||
continue;
|
||||
}
|
||||
$array[$key] = (new File($file['tmp_name']))->setUploadInfo($file);
|
||||
}
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
if (strpos($name, '.')) {
|
||||
list($name, $sub) = explode('.', $name);
|
||||
}
|
||||
if ('' === $name) {
|
||||
// 获取全部文件
|
||||
return $array;
|
||||
} elseif (isset($sub) && isset($array[$name][$sub])) {
|
||||
return $array[$name][$sub];
|
||||
} elseif (isset($array[$name])) {
|
||||
if ($array[$name] instanceof File) {
|
||||
return $array[$name];
|
||||
} elseif (!empty($array[$name]['tmp_name'])) {
|
||||
return (new File($array[$name]['tmp_name']))->setUploadInfo($array[$name]);
|
||||
}
|
||||
return $array[$name];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -861,7 +865,7 @@ class Request
|
||||
} elseif (empty($this->env)) {
|
||||
$this->env = $_ENV;
|
||||
}
|
||||
return false === $name ? $this->env : $this->input($this->env, strtoupper($name), $default, $filter);
|
||||
return $this->input($this->env, false === $name ? false : strtoupper($name), $default, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -902,13 +906,17 @@ class Request
|
||||
/**
|
||||
* 获取变量 支持过滤和默认值
|
||||
* @param array $data 数据源
|
||||
* @param string $name 字段名
|
||||
* @param string|false $name 字段名
|
||||
* @param mixed $default 默认值
|
||||
* @param string|array $filter 过滤函数
|
||||
* @return mixed
|
||||
*/
|
||||
public function input($data = [], $name = '', $default = null, $filter = null)
|
||||
{
|
||||
if (false === $name) {
|
||||
// 获取原始数据
|
||||
return $data;
|
||||
}
|
||||
$name = (string) $name;
|
||||
if ('' != $name) {
|
||||
// 解析name
|
||||
|
||||
174
core/library/think/db/connector/Firebird.php
Normal file
174
core/library/think/db/connector/Firebird.php
Normal file
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: weianguo <366958903@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\db\connector;
|
||||
|
||||
use PDO;
|
||||
use think\db\Connection;
|
||||
use think\Log;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\exception\PDOException;
|
||||
|
||||
/**
|
||||
* firebird数据库驱动
|
||||
*/
|
||||
class Firebird extends Connection
|
||||
{
|
||||
|
||||
/**
|
||||
* 解析pdo连接的dsn信息
|
||||
* @access public
|
||||
* @param array $config 连接信息
|
||||
* @return string
|
||||
*/
|
||||
protected function parseDsn($config)
|
||||
{
|
||||
$dsn = 'firebird:dbname=' . $config['hostname'].'/'.$config['hostport'].':'.$config['database'];
|
||||
return $dsn;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得数据表的字段信息
|
||||
* @access public
|
||||
* @param string $tableName
|
||||
* @return array
|
||||
*/
|
||||
public function getFields($tableName)
|
||||
{
|
||||
$this->initConnect(true);
|
||||
list($tableName) = explode(' ', $tableName);
|
||||
$sql= 'SELECT TRIM(RF.RDB$FIELD_NAME) AS FIELD,RF.RDB$DEFAULT_VALUE AS DEFAULT1,RF.RDB$NULL_FLAG AS NULL1,TRIM(T.RDB$TYPE_NAME) || \'(\' || F.RDB$FIELD_LENGTH || \')\' as TYPE FROM RDB$RELATION_FIELDS RF LEFT JOIN RDB$FIELDS F ON (F.RDB$FIELD_NAME = RF.RDB$FIELD_SOURCE) LEFT JOIN RDB$TYPES T ON (T.RDB$TYPE = F.RDB$FIELD_TYPE) WHERE RDB$RELATION_NAME=UPPER(\'' . $tableName . '\') AND T.RDB$FIELD_NAME = \'RDB$FIELD_TYPE\' ORDER By RDB$FIELD_POSITION';
|
||||
$result = $this->linkID->query($sql);
|
||||
$info = [];
|
||||
if ($result) {
|
||||
foreach ($result as $key => $val) {
|
||||
$info[$val[0]] = array(
|
||||
'name' => $val[0],
|
||||
'type' => $val[3],
|
||||
'notnull' => ($val[2]==1),
|
||||
'default' => $val[1],
|
||||
'primary' => false,
|
||||
'autoinc' => false,
|
||||
);
|
||||
}
|
||||
}
|
||||
//获取主键
|
||||
$sql = 'select TRIM(b.rdb$field_name) as field_name from rdb$relation_constraints a join rdb$index_segments b on a.rdb$index_name=b.rdb$index_name where a.rdb$constraint_type=\'PRIMARY KEY\' and a.rdb$relation_name=UPPER(\'' . $tableName . '\')';
|
||||
$rs_temp = $this->linkID->query($sql);
|
||||
foreach ($rs_temp as $row) {
|
||||
$info[$row[0]]['primary'] = true;
|
||||
}
|
||||
return $this->fieldCase($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得数据库的表信息
|
||||
* @access public
|
||||
* @param string $dbName
|
||||
* @return array
|
||||
*/
|
||||
public function getTables($dbName = '')
|
||||
{
|
||||
$sql = 'SELECT DISTINCT RDB$RELATION_NAME FROM RDB$RELATION_FIELDS WHERE RDB$SYSTEM_FLAG=0';
|
||||
$result = $this->query($sql);
|
||||
$info = [];
|
||||
foreach ($result as $key => $val) {
|
||||
$info[$key] = trim(current($val));
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行语句
|
||||
* @access public
|
||||
* @param string $sql sql指令
|
||||
* @param array $bind 参数绑定
|
||||
* @param boolean $getLastInsID 是否获取自增ID
|
||||
* @param string $sequence 自增序列名
|
||||
* @return int
|
||||
* @throws BindParamException
|
||||
* @throws PDOException
|
||||
*/
|
||||
public function execute($sql, $bind = [], $getLastInsID = false, $sequence = null)
|
||||
{
|
||||
$this->initConnect(true);
|
||||
if (!$this->linkID) {
|
||||
return false;
|
||||
}
|
||||
// 根据参数绑定组装最终的SQL语句
|
||||
$this->queryStr = $this->getRealSql($sql, $bind);
|
||||
|
||||
//释放前次的查询结果
|
||||
if (!empty($this->PDOStatement)) {
|
||||
$this->free();
|
||||
}
|
||||
|
||||
$bind=array_map(function($v){
|
||||
return array_map(function($v2){
|
||||
return mb_convert_encoding($v2,'gbk','utf-8');},$v);
|
||||
},$bind);
|
||||
|
||||
Db::$executeTimes++;
|
||||
try {
|
||||
// 调试开始
|
||||
$this->debug(true);
|
||||
// 预处理
|
||||
$this->PDOStatement = $this->linkID->prepare(mb_convert_encoding($sql,'gbk','utf-8'));
|
||||
// 参数绑定操作
|
||||
$this->bindValue($bind);
|
||||
// 执行语句
|
||||
$result = $this->PDOStatement->execute();
|
||||
// 调试结束
|
||||
$this->debug(false);
|
||||
|
||||
$this->numRows = $this->PDOStatement->rowCount();
|
||||
return $this->numRows;
|
||||
} catch (\PDOException $e) {
|
||||
throw new PDOException($e, $this->config, $this->queryStr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动事务
|
||||
* @access public
|
||||
* @return bool|null
|
||||
*/
|
||||
public function startTrans()
|
||||
{
|
||||
$this->initConnect(true);
|
||||
if (!$this->linkID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
++$this->transTimes;
|
||||
|
||||
if (1 == $this->transTimes) {
|
||||
$this->linkID->setAttribute(\PDO::ATTR_AUTOCOMMIT,false);
|
||||
$this->linkID->beginTransaction();
|
||||
} elseif ($this->transTimes > 1 && $this->supportSavepoint()) {
|
||||
$this->linkID->exec(
|
||||
$this->parseSavepoint('trans' . $this->transTimes)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL性能分析
|
||||
* @access protected
|
||||
* @param string $sql
|
||||
* @return array
|
||||
*/
|
||||
protected function getExplain($sql)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class File
|
||||
// 检测模板目录
|
||||
$dir = dirname($cacheFile);
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0777, true);
|
||||
mkdir($dir, 0644, true);
|
||||
}
|
||||
// 生成模板缓存文件
|
||||
if (false === file_put_contents($cacheFile, $content)) {
|
||||
|
||||
Reference in New Issue
Block a user