Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
Settings | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
disableWrite | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
isWriteDisabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setSessionManager | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Container for session settings, allowing those settings to be configured |
5 | * "just in case" they are needed, without invoking the heavy weight of |
6 | * instantiating the session itself. See \VuFind\Session\ManagerFactory for |
7 | * details on the use of this object. |
8 | * |
9 | * PHP version 8 |
10 | * |
11 | * Copyright (C) Villanova University 2016. |
12 | * |
13 | * This program is free software; you can redistribute it and/or modify |
14 | * it under the terms of the GNU General Public License version 2, |
15 | * as published by the Free Software Foundation. |
16 | * |
17 | * This program is distributed in the hope that it will be useful, |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 | * GNU General Public License for more details. |
21 | * |
22 | * You should have received a copy of the GNU General Public License |
23 | * along with this program; if not, write to the Free Software |
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
25 | * |
26 | * @category VuFind |
27 | * @package Session_Handlers |
28 | * @author Demian Katz <demian.katz@villanova.edu> |
29 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
30 | * @link https://vufind.org/wiki/development Wiki |
31 | */ |
32 | |
33 | namespace VuFind\Session; |
34 | |
35 | use Laminas\Session\SessionManager; |
36 | |
37 | use function is_callable; |
38 | |
39 | /** |
40 | * Container for session settings, allowing those settings to be configured |
41 | * "just in case" they are needed, without invoking the heavy weight of |
42 | * instantiating the session itself. See \VuFind\Session\ManagerFactory for |
43 | * details on the use of this object. |
44 | * |
45 | * @category VuFind |
46 | * @package Session_Handlers |
47 | * @author Demian Katz <demian.katz@villanova.edu> |
48 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
49 | * @link https://vufind.org/wiki/development Wiki |
50 | */ |
51 | class Settings |
52 | { |
53 | /** |
54 | * Have session writes been disabled? |
55 | * |
56 | * @var bool |
57 | */ |
58 | protected $disableWrite = false; |
59 | |
60 | /** |
61 | * Session manager (if instantiated) |
62 | * |
63 | * @var SessionManager |
64 | */ |
65 | protected $manager = null; |
66 | |
67 | /** |
68 | * Disable session writes after this point in time. |
69 | * |
70 | * @return void |
71 | */ |
72 | public function disableWrite() |
73 | { |
74 | // Set the flag |
75 | $this->disableWrite = true; |
76 | |
77 | // If the session manager is already instantiated, close it! |
78 | if (null !== $this->manager) { |
79 | // Try to disable writes so that writeClose() below doesn't actually |
80 | // write anything: |
81 | $saveHandler = $this->manager->getSaveHandler(); |
82 | if (is_callable([$saveHandler, 'disableWrites'])) { |
83 | $saveHandler->disableWrites(); |
84 | } |
85 | // Close the session: |
86 | $this->manager->writeClose(); |
87 | } |
88 | } |
89 | |
90 | /** |
91 | * Have session writes been disabled? |
92 | * |
93 | * @return bool |
94 | */ |
95 | public function isWriteDisabled() |
96 | { |
97 | return $this->disableWrite; |
98 | } |
99 | |
100 | /** |
101 | * Set a session manager instance. |
102 | * |
103 | * @param SessionManager $sessionManager Session manager |
104 | * |
105 | * @return Settings |
106 | */ |
107 | public function setSessionManager(SessionManager $sessionManager) |
108 | { |
109 | $this->manager = $sessionManager; |
110 | return $this; |
111 | } |
112 | } |