|
1
|
|
|
<?php |
|
2
|
|
|
// +---------------------------------------------------------------------- |
|
3
|
|
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ] |
|
4
|
|
|
// +---------------------------------------------------------------------- |
|
5
|
|
|
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved. |
|
6
|
|
|
// +---------------------------------------------------------------------- |
|
7
|
|
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) |
|
8
|
|
|
// +---------------------------------------------------------------------- |
|
9
|
|
|
// | Author: liu21st <[email protected]> |
|
10
|
|
|
// +---------------------------------------------------------------------- |
|
11
|
|
|
declare (strict_types = 1); |
|
12
|
|
|
|
|
13
|
|
|
namespace think; |
|
14
|
|
|
|
|
15
|
|
|
use think\helper\Arr; |
|
16
|
|
|
use think\session\Store; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Session管理类 |
|
20
|
|
|
* @package think |
|
|
|
|
|
|
21
|
|
|
* @mixin Store |
|
22
|
|
|
*/ |
|
23
|
|
|
class Session extends Manager |
|
24
|
|
|
{ |
|
25
|
|
|
protected $namespace = '\\think\\session\\driver\\'; |
|
26
|
|
|
|
|
27
|
6 |
|
protected function createDriver(string $name) |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
6 |
|
$handler = parent::createDriver($name); |
|
30
|
|
|
|
|
31
|
6 |
|
return new Store($this->getConfig('name', 'PHPSESSID'), $handler, $this->getConfig('serialize')); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* 获取Session配置 |
|
36
|
|
|
* @access public |
|
37
|
|
|
* @param null|string $name 名称 |
|
38
|
|
|
* @param mixed $default 默认值 |
|
39
|
|
|
* @return mixed |
|
40
|
|
|
*/ |
|
41
|
6 |
|
public function getConfig(string $name = null, $default = null) |
|
42
|
|
|
{ |
|
43
|
6 |
|
if (!is_null($name)) { |
|
44
|
6 |
|
return $this->app->config->get('session.' . $name, $default); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return $this->app->config->get('session'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
6 |
|
protected function resolveConfig(string $name) |
|
|
|
|
|
|
51
|
|
|
{ |
|
52
|
6 |
|
$config = $this->app->config->get('session', []); |
|
53
|
6 |
|
Arr::forget($config, 'type'); |
|
54
|
6 |
|
return $config; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* 默认驱动 |
|
59
|
|
|
* @return string|null |
|
60
|
|
|
*/ |
|
61
|
6 |
|
public function getDefaultDriver() |
|
62
|
|
|
{ |
|
63
|
6 |
|
return $this->app->config->get('session.type', 'file'); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|