我是靠谱客的博主 俊秀发夹,这篇文章主要介绍分享几个 Hyperf 常用助手函数,现在分享给大家,希望可以做个参考。

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

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php use HyperfContractStdoutLoggerInterface; use HyperfHttpServerContractResponseInterface; use HyperfLoggerLoggerFactory; use HyperfServerServerFactory; use HyperfUtilsApplicationContext; use PsrHttpMessageServerRequestInterface; use SwooleWebsocketFrame; use SwooleWebSocketServer 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(PsrSimpleCacheCacheInterface::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 常用助手函数的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是俊秀发夹最近收集整理的关于分享几个 Hyperf 常用助手函数的全部内容,更多相关分享几个内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(96)

评论列表共有 0 条评论

立即
投稿
返回
顶部