Completed
Push — 6.0 ( b72c2e...58dbb9 )
by yun
05:58
created

Session::getConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
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
0 ignored issues
show
Coding Style introduced by
Package name "think" is not valid; consider "Think" instead
Loading history...
21
 * @mixin Store
22
 */
23
class Session extends Manager
24
{
25
    protected $namespace = '\\think\\session\\driver\\';
26
27 6
    protected function createDriver(string $name)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function createDriver()
Loading history...
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)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function resolveConfig()
Loading history...
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');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->app->confi...'session.type', 'file') also could return the type array which is incompatible with the documented return type null|string.
Loading history...
64
    }
65
}
66