找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 php教程 查看内容

分享几个Hyperf常用助手函数

作者:模板之家 2020-10-28 16:34 12251人关注

使用hyperf已经有一段时间了,下面是一些常用的助手函数,有需要的可以参考一下!,分享几个Hyperf常用助手函数

使用 hyperf 已经有一段时间了,下面是一些常用的助手函数,分享一下~~~

get(Redis::class);
    }
}

/**
 * server 实例 基于 swoole server
 */
if (!function_exists('server')) {
    function server()
    {
        return container()->get(ServerFactory::class)->getServer()->getServer();
    }
}

/**
 * websocket frame 实例
 */
if (!function_exists('frame')) {
    function frame()
    {
        return container()->get(Frame::class);
    }
}

/**
 * websocket 实例
 */
if (!function_exists('websocket')) {
    function websocket()
    {
        return container()->get(WebSocketServer::class);
    }
}

/**
 * 缓存实例 简单的缓存
 */
if (!function_exists('cache')) {
    function cache()
    {
        return container()->get(Psr\SimpleCache\CacheInterface::class);
    }
}

/**
 * 控制台日志
 */
if (!function_exists('stdLog')) {
    function stdLog()
    {
        return container()->get(StdoutLoggerInterface::class);
    }
}

/**
 * 文件日志
 */
if (!function_exists('logger')) {
    function logger()
    {
        return container()->get(LoggerFactory::class)->make();
    }
}

/**
 *
 */
if (!function_exists('request')) {
    function request()
    {
        return container()->get(ServerRequestInterface::class);
    }
}

/**
 *
 */
if (!function_exists('response')) {
    function response()
    {
        return container()->get(ResponseInterface::class);
    }
}

推荐教程:《PHP教程》

以上就是分享几个 Hyperf 常用助手函数的详细内容,更多请关注 模板之家(www.mb5.com.cn) 其它相关文章!


路过

雷人

握手

鲜花

鸡蛋
原作者: 互联网 来自: 网络收集

全部回复(0)