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

Cache::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
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: yunwuxin <[email protected]>
10
// +----------------------------------------------------------------------
11
namespace think\session\driver;
12
13
use Psr\SimpleCache\CacheInterface;
14
use think\contract\SessionHandlerInterface;
15
use think\helper\Arr;
16
17
class Cache implements SessionHandlerInterface
18
{
19
20
    /** @var CacheInterface */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
21
    protected $handler;
22
23
    /** @var integer */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
24
    protected $expire;
25
26
    /** @var string */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
27
    protected $prefix;
28
29 1
    public function __construct(\think\Cache $cache, array $config = [])
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
30
    {
31 1
        $this->handler = $cache->store(Arr::get($config, 'store'));
32 1
        $this->expire  = Arr::get($config, 'expire', 1440);
33 1
        $this->prefix  = Arr::get($config, 'prefix', '');
34 1
    }
35
36 1
    public function read(string $sessionId): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function read()
Loading history...
37
    {
38 1
        return (string) $this->handler->get($this->prefix . $sessionId);
39
    }
40
41 1
    public function delete(string $sessionId): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function delete()
Loading history...
42
    {
43 1
        return $this->handler->delete($this->prefix . $sessionId);
44
    }
45
46 1
    public function write(string $sessionId, string $data): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function write()
Loading history...
47
    {
48 1
        return $this->handler->set($this->prefix . $sessionId, $data, $this->expire);
49
    }
50
}
51