栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

helper.php-1

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

helper.php-1

//------------------------

// ThinkPHP 助手函数

//-------------------------

 

use thinkCache;// 加载 Cache 类型

use thinkConfig;// 加载配置文件类

use thinkcookie;// 加载 cookie

use thinkDb;// 加载 Db

use thinkDebug;// 加载 Debug

use thinkexceptionHttpException;// 加载 异常

use thinkexceptionHttpResponseException;// 加载 异常

use thinkLang;// 加载 语言

use thinkLoader;// 加载 加载文件

use thinkLog;// 加载 日志

use thinkRequest;// 请求

use thinkResponse;// 回应

use thinkSession;//Session

use thinkUrl;// Url

use thinkView;// View

 

// 作为一个helper 使用了很多的 东西

// a new namespace 用法

 

if (!function_exists('load_trait')) {

   

    function load_trait($class, $ext = EXT)

    {

        return Loader::import($class, TRAIT_PATH, $ext);// a trap function about this loader class and this import function

    }// 加载文件,按照 不同的 标准类型

}

 

if (!function_exists('exception')) {

   

    function exception($msg, $code = 0, $exception = '')

    {

        $e = $exception ?: 'thinkException';// 使用异常处理类

        throw new $e($msg, $code);//抛出 新异常

    }// 异常 出来

}

 

if (!function_exists('debug')) {

   

    function debug($start, $end = '', $dec = 6)

    {

        if ('' == $end) {

            Debug::remark($start);// Debug::

        } else {

            return 'm' == $dec ? Debug::getRangeMem($start, $end) : Debug::getRangeTime($start, $end, $dec);

        }// 如果是 m 的话,则记录的是 getRangeMem

    }

}

 

if (!function_exists('lang')) {

   

    function lang($name, $vars = [], $lang = '')

    {

        return Lang::get($name, $vars, $lang);// 获取语言配置, 对类的二次封装

        // 这个版本 对比 3的版本 发现了 更多功能隐藏在了 class 里面,更多的面向对象了

    }

}

 

if (!function_exists('config')) {

   

    function config($name = '', $value = null, $range = '')

    {

        if (is_null($value) && is_string($name)) {

            return 0 === strpos($name, '?') ? Config::has(substr($name, 1), $range) : Config::get($name, $range);

            // 中国 第一 超强 配置,太牛叉了,不错 通过不同的配置项,让 自己的函数 具有更强的功能

        } else {

            return Config::set($name, $value, $range);// other 否则 去设置 对应的 文件

        }

    }

}

 

if (!function_exists('input')) {

   

    function input($key = '', $default = null, $filter = null)

    {

        if (0 === strpos($key, '?')) {

            $key = substr($key, 1);

            $has = true;

        }// 判读 时候 包含 这个 输入 input 好巴适,去掉了 更多 浮躁,更多的融入了这个代码

        if ($pos = strpos($key, '.')) {// 如果有这些 比如 input('get.ok')

            // 指定参数来源

            $method = substr($key, 0, $pos);

            if (in_array($method, ['get', 'post', 'put', 'patch', 'delete', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) {

                $key = substr($key, $pos + 1);

            } else {

                $method = 'param';

            }

            // 当非明确来源的时候,显示通用的来源

        } else {

            // 默认为自动判断

            $method = 'param';// 默认也是这个

        }

        if (isset($has)) {

            return request()->has($key, $method, $default);// 如果是 ?get.ok 去判读是否有这个

        } else {

            return request()->$method($key, $default, $filter);// 否则返回数据

            // 比如 request()->get('ok','123','htmlspechialchar');

        }

    }

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/229282.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号