Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Session;
4
 
5
use Illuminate\Contracts\Cache\Repository as CacheContract;
6
use SessionHandlerInterface;
7
 
8
class CacheBasedSessionHandler implements SessionHandlerInterface
9
{
10
    /**
11
     * The cache repository instance.
12
     *
13
     * @var \Illuminate\Contracts\Cache\Repository
14
     */
15
    protected $cache;
16
 
17
    /**
18
     * The number of minutes to store the data in the cache.
19
     *
20
     * @var int
21
     */
22
    protected $minutes;
23
 
24
    /**
25
     * Create a new cache driven handler instance.
26
     *
27
     * @param  \Illuminate\Contracts\Cache\Repository  $cache
28
     * @param  int  $minutes
29
     * @return void
30
     */
31
    public function __construct(CacheContract $cache, $minutes)
32
    {
33
        $this->cache = $cache;
34
        $this->minutes = $minutes;
35
    }
36
 
37
    /**
38
     * {@inheritdoc}
39
     *
40
     * @return bool
41
     */
42
    public function open($savePath, $sessionName): bool
43
    {
44
        return true;
45
    }
46
 
47
    /**
48
     * {@inheritdoc}
49
     *
50
     * @return bool
51
     */
52
    public function close(): bool
53
    {
54
        return true;
55
    }
56
 
57
    /**
58
     * {@inheritdoc}
59
     *
60
     * @return string
61
     */
62
    public function read($sessionId): string
63
    {
64
        return $this->cache->get($sessionId, '');
65
    }
66
 
67
    /**
68
     * {@inheritdoc}
69
     *
70
     * @return bool
71
     */
72
    public function write($sessionId, $data): bool
73
    {
74
        return $this->cache->put($sessionId, $data, $this->minutes * 60);
75
    }
76
 
77
    /**
78
     * {@inheritdoc}
79
     *
80
     * @return bool
81
     */
82
    public function destroy($sessionId): bool
83
    {
84
        return $this->cache->forget($sessionId);
85
    }
86
 
87
    /**
88
     * {@inheritdoc}
89
     *
90
     * @return int
91
     */
92
    public function gc($lifetime): int
93
    {
94
        return 0;
95
    }
96
 
97
    /**
98
     * Get the underlying cache repository.
99
     *
100
     * @return \Illuminate\Contracts\Cache\Repository
101
     */
102
    public function getCache()
103
    {
104
        return $this->cache;
105
    }
106
}