Skip to content

Commit 93f02a6

Browse files
committed
规范Session配置参数
1 parent cec044f commit 93f02a6

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

App/WebSocket/Base.php

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,24 @@ class Base extends Controller
1616
/**
1717
* Session操作
1818
* @param string $key
19-
* @param string $data
19+
* @param mixed $data
2020
* @return bool|mixed|null
2121
* @throws \EasySwoole\Redis\Exception\RedisException
2222
*/
2323
public function session(string $key = SWORD_NULL, $data = SWORD_NULL)
2424
{
2525
$args = $this->caller()->getArgs();
2626

27-
$sname = config('session.sessionName');
28-
if(empty($args[$sname])){
27+
$name = config('session.session_name');
28+
if(empty($args[$name])){
2929
return false;
3030
}
3131

32-
if(empty($args[$sname])) return false;
32+
if(empty($args[$name])) return false;
3333

34-
$value = cache($args[$sname]);
34+
$token = $args[$name];
35+
36+
$value = cache($token);
3537
if(!$value) return false;
3638

3739
if($key == SWORD_NULL){
@@ -40,10 +42,10 @@ public function session(string $key = SWORD_NULL, $data = SWORD_NULL)
4042
return $value[$key] ?? null;
4143
}elseif($data == null){
4244
unset($value[$key]);
43-
cache($args[$sname], $value);
45+
cache($token, $value);
4446
}else{
4547
$value[$key] = $data;
46-
cache($args[$sname], $value);
48+
cache($token, $value);
4749
}
4850
return true;
4951
}
@@ -56,11 +58,11 @@ public function sessionId()
5658
{
5759
$args = $this->caller()->getArgs();
5860

59-
$sname = config('session.sessionName');
60-
if(empty($args[$sname])){
61+
$name = config('session.session_name');
62+
if(empty($args[$name])){
6163
return false;
6264
}
63-
return $args[$sname];
65+
return $args[$name];
6466
}
6567

6668
/**
@@ -88,8 +90,18 @@ public function withData(int $code = 0, string $msg = '', $result = [], int $cou
8890
$ret['ES_TOKEN'] = $args['ES_TOKEN'];
8991
}
9092

91-
$this->response()->setMessage(json_encode($ret));
93+
$this->responseImmediately(json_encode($ret));
9294
return true;
9395
}
9496

97+
/**
98+
* 获取上传数据
99+
* @return array
100+
*/
101+
public function input(): array
102+
{
103+
$args = $this->caller()->getArgs();
104+
return $args['data']??[];
105+
}
106+
95107
}

Config/session.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
return [
66
'enable' => true, //启用Session
77
'type' => 'file', //储存驱动 redis、file
8-
'sessionName' => 'sessionId', //Session的CookieName
8+
'session_name' => 'sessionId', //Session的CookieName
99
'expire' => 86400 * 7 //过期时间 s
1010
];

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ php sword server stop
7070

7171
## 项目结构
7272
```
73-
PATH 部署目录
73+
PATH 项目根目录
7474
├─App 应用目录
7575
│ ├─HttpController Http控制器
7676
│ ├─WebSocket WebSocket控制器

0 commit comments

Comments
 (0)