应用 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 php开发教程 php开发资料 php开发自学 hyperf
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!