分享几个 Hyperf 常用助手函数
导读:收集整理的这篇文章主要介绍了分享几个 Hyperf 常用助手函数,觉得挺不错的,现在分享给大家,也给大家做个参考。 使用 Hype...
收集整理的这篇文章主要介绍了分享几个 Hyperf 常用助手函数,觉得挺不错的,现在分享给大家,也给大家做个参考。
使用 Hyperf 已经有一段时间了,下面是一些常用的助手函数,分享一下~~~
?phpuse 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 常用助手函数的详细内容,更多请关注其它相关文章!
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 分享几个 Hyperf 常用助手函数
本文地址: https://pptw.com/jishu/596469.html
