@@ -50,7 +50,7 @@ class SocketV2 implements LogHandlerInterface
50
50
51
51
protected array $ allowForceClientIds = []; //配置强制推送且被授权的client_id
52
52
53
- protected $ clientArg = [];
53
+ private array $ clientArg = [];
54
54
55
55
protected App $ app ;
56
56
protected SocketClient $ client ;
@@ -159,7 +159,7 @@ public function save(array $log = []): bool
159
159
'css ' => '' ,
160
160
];
161
161
162
- $ tabid = $ this ->getClientArg ('tabid ' );
162
+ $ tabId = ( int ) $ this ->getClientArg ('tabid ' );
163
163
164
164
if (!$ clientId = $ this ->getClientArg ('client_id ' )) {
165
165
$ clientId = '' ;
@@ -169,10 +169,10 @@ public function save(array $log = []): bool
169
169
//强制推送到多个client_id
170
170
foreach ($ this ->allowForceClientIds as $ forceClientId ) {
171
171
$ clientId = $ forceClientId ;
172
- $ this ->sendToClient ($ tabid , $ clientId , $ trace , $ forceClientId );
172
+ $ this ->sendToClient ($ tabId , $ clientId , $ trace , $ forceClientId );
173
173
}
174
174
} else {
175
- $ this ->sendToClient ($ tabid , $ clientId , $ trace , '' );
175
+ $ this ->sendToClient ($ tabId , $ clientId , $ trace , '' );
176
176
}
177
177
178
178
return true ;
@@ -204,14 +204,13 @@ protected function sendToClient($tabId, $clientId, $logs, $forceClientId)
204
204
205
205
/**
206
206
* 检测客户授权
207
- * @return bool
208
207
*/
209
- protected function check ()
208
+ protected function check (): bool
210
209
{
211
- $ tabid = $ this ->getClientArg ('tabid ' );
210
+ $ tabid = ( int ) $ this ->getClientArg ('tabid ' );
212
211
213
212
//是否记录日志的检查
214
- if (! $ tabid && !$ this ->config ['force_client_ids ' ]) {
213
+ if ($ tabid === 0 && !$ this ->config ['force_client_ids ' ]) {
215
214
return false ;
216
215
}
217
216
@@ -238,10 +237,8 @@ protected function check()
238
237
239
238
/**
240
239
* 获取客户参数
241
- * @param string $name
242
- * @return string
243
240
*/
244
- protected function getClientArg (string $ name )
241
+ protected function getClientArg (string $ name ): string
245
242
{
246
243
if (!$ this ->app ->exists ('request ' )) {
247
244
return '' ;
@@ -254,10 +251,18 @@ protected function getClientArg(string $name)
254
251
}
255
252
256
253
if (!preg_match ('/SocketLog\((.*?)\)/ ' , $ socketLog , $ match )) {
257
- $ this ->clientArg = ['tabid ' => null , 'client_id ' => null ];
254
+ $ this ->clientArg = [
255
+ 'tabid ' => '-1 ' ,
256
+ 'client_id ' => null ,
257
+ ];
258
258
return '' ;
259
259
}
260
- parse_str ($ match [1 ] ?? '' , $ this ->clientArg );
260
+ $ tmp = [];
261
+ parse_str ($ match [1 ] ?? '' , $ tmp );
262
+ $ this ->clientArg = [
263
+ 'tabid ' => $ tmp ['tabid ' ] ?? '-1 ' ,
264
+ 'client_id ' => $ tmp ['client_id ' ] ?? null ,
265
+ ];
261
266
}
262
267
263
268
if (isset ($ this ->clientArg [$ name ])) {
0 commit comments