分享几个 Hyperf 常用助手函数
Jun 19, 2020 pm 06:08 PM
hyperf
php
使用 hyperf 已经有一段时间了,下面是一些常用的助手函数,分享一下~~~
<?php use Hyperf\Contract\StdoutLoggerInterface; use Hyperf\HttpServer\Contract\ResponseInterface; use Hyperf\Logger\LoggerFactory; use Hyperf\Server\ServerFactory; use Hyperf\Utils\ApplicationContext; use Psr\Http\Message\ServerRequestInterface; use Swoole\Websocket\Frame; use Swoole\WebSocket\Server as WebSocketServer; /** * 容器实例 */ if (!function_exists('container')) { function container() { return ApplicationContext::getContainer(); } } /** * redis 客户端实例 */ if (!function_exists('redis')) { function redis() { return container()->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 常用助手函数的详细内容。更多信息请关注PHP中文网其他相关文章!
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章
仓库:如何复兴队友
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
击败分裂小说需要多长时间?
3 周前
By DDD
公众号网页更新缓存难题:如何避免版本更新后旧缓存影响用户体验?
3 周前
By 王林

热门文章
仓库:如何复兴队友
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
击败分裂小说需要多长时间?
3 周前
By DDD
公众号网页更新缓存难题:如何避免版本更新后旧缓存影响用户体验?
3 周前
By 王林

热门文章标签

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

适用于 Ubuntu 和 Debian 的 PHP 8.4 安装和升级指南

如何设置 Visual Studio Code (VS Code) 进行 PHP 开发
