forked from illuminate/session
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CookieSessionHandler.php
executable file
·96 lines (84 loc) · 1.82 KB
/
CookieSessionHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace Illuminate\Session;
use SessionHandlerInterface;
use Symfony\Component\HttpFoundation\Request;
use Illuminate\Contracts\Cookie\QueueingFactory as CookieJar;
class CookieSessionHandler implements SessionHandlerInterface
{
/**
* The cookie jar instance.
*
* @var \Illuminate\Contracts\Cookie\Factory
*/
protected $cookie;
/**
* The request instance.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* Create a new cookie driven handler instance.
*
* @param \Illuminate\Contracts\Cookie\QueueingFactory $cookie
* @param int $minutes
* @return void
*/
public function __construct(CookieJar $cookie, $minutes)
{
$this->cookie = $cookie;
$this->minutes = $minutes;
}
/**
* {@inheritDoc}
*/
public function open($savePath, $sessionName)
{
return true;
}
/**
* {@inheritDoc}
*/
public function close()
{
return true;
}
/**
* {@inheritDoc}
*/
public function read($sessionId)
{
return $this->request->cookies->get($sessionId) ?: '';
}
/**
* {@inheritDoc}
*/
public function write($sessionId, $data)
{
$this->cookie->queue($sessionId, $data, $this->minutes);
}
/**
* {@inheritDoc}
*/
public function destroy($sessionId)
{
$this->cookie->queue($this->cookie->forget($sessionId));
}
/**
* {@inheritDoc}
*/
public function gc($lifetime)
{
return true;
}
/**
* Set the request instance.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @return void
*/
public function setRequest(Request $request)
{
$this->request = $request;
}
}