Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | af1871eacc83 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Core\Session; | |
4 | |
5 /** | |
6 * Wraps another SessionHandlerInterface to prevent writes when not allowed. | |
7 */ | |
8 class WriteSafeSessionHandler implements \SessionHandlerInterface, WriteSafeSessionHandlerInterface { | |
9 | |
10 /** | |
11 * @var \SessionHandlerInterface | |
12 */ | |
13 protected $wrappedSessionHandler; | |
14 | |
15 /** | |
16 * Whether or not the session is enabled for writing. | |
17 * | |
18 * @var bool | |
19 */ | |
20 protected $sessionWritable; | |
21 | |
22 /** | |
23 * Constructs a new write safe session handler. | |
24 * | |
25 * @param \SessionHandlerInterface $wrapped_session_handler | |
26 * The underlying session handler. | |
27 * @param bool $session_writable | |
28 * Whether or not the session should be initially writable. | |
29 */ | |
30 public function __construct(\SessionHandlerInterface $wrapped_session_handler, $session_writable = TRUE) { | |
31 $this->wrappedSessionHandler = $wrapped_session_handler; | |
32 $this->sessionWritable = $session_writable; | |
33 } | |
34 | |
35 /** | |
36 * {@inheritdoc} | |
37 */ | |
38 public function close() { | |
39 return $this->wrappedSessionHandler->close(); | |
40 } | |
41 | |
42 /** | |
43 * {@inheritdoc} | |
44 */ | |
45 public function destroy($session_id) { | |
46 return $this->wrappedSessionHandler->destroy($session_id); | |
47 } | |
48 | |
49 /** | |
50 * {@inheritdoc} | |
51 */ | |
52 public function gc($max_lifetime) { | |
53 return $this->wrappedSessionHandler->gc($max_lifetime); | |
54 } | |
55 | |
56 /** | |
57 * {@inheritdoc} | |
58 */ | |
59 public function open($save_path, $session_id) { | |
60 return $this->wrappedSessionHandler->open($save_path, $session_id); | |
61 } | |
62 | |
63 /** | |
64 * {@inheritdoc} | |
65 */ | |
66 public function read($session_id) { | |
67 return $this->wrappedSessionHandler->read($session_id); | |
68 } | |
69 | |
70 /** | |
71 * {@inheritdoc} | |
72 */ | |
73 public function write($session_id, $session_data) { | |
74 if ($this->isSessionWritable()) { | |
75 return $this->wrappedSessionHandler->write($session_id, $session_data); | |
76 } | |
77 else { | |
78 return TRUE; | |
79 } | |
80 } | |
81 | |
82 /** | |
83 * {@inheritdoc} | |
84 */ | |
85 public function setSessionWritable($flag) { | |
86 $this->sessionWritable = (bool) $flag; | |
87 } | |
88 | |
89 /** | |
90 * {@inheritdoc} | |
91 */ | |
92 public function isSessionWritable() { | |
93 return $this->sessionWritable; | |
94 } | |
95 | |
96 } |