Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
6 / 6 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
Session | |
100.00% |
6 / 6 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
__invoke | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
put | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * Session view helper |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) The National Library of Finland 2023. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package View_Helpers |
25 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org/wiki/development Wiki |
28 | */ |
29 | |
30 | namespace VuFind\View\Helper\Root; |
31 | |
32 | use Laminas\Session\Container as SessionContainer; |
33 | |
34 | /** |
35 | * Session view helper |
36 | * |
37 | * @category VuFind |
38 | * @package View_Helpers |
39 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
40 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
41 | * @link https://vufind.org/wiki/development Wiki |
42 | */ |
43 | class Session extends \Laminas\View\Helper\AbstractHelper |
44 | { |
45 | /** |
46 | * Session container |
47 | * |
48 | * @var SessionContainer |
49 | */ |
50 | protected $sessionContainer; |
51 | |
52 | /** |
53 | * Config constructor. |
54 | * |
55 | * @param SessionContainer $sessionContainer Session container |
56 | */ |
57 | public function __construct(SessionContainer $sessionContainer) |
58 | { |
59 | $this->sessionContainer = $sessionContainer; |
60 | } |
61 | |
62 | /** |
63 | * Return this object |
64 | * |
65 | * @return Session |
66 | */ |
67 | public function __invoke(): Session |
68 | { |
69 | return $this; |
70 | } |
71 | |
72 | /** |
73 | * Get an item from the session container |
74 | * |
75 | * @param string $name Item name |
76 | * |
77 | * @return mixed |
78 | */ |
79 | public function get(string $name) |
80 | { |
81 | return $this->sessionContainer->$name ?? null; |
82 | } |
83 | |
84 | /** |
85 | * Put an item to the session container |
86 | * |
87 | * @param string $name Item name |
88 | * @param mixed $value Item value |
89 | * |
90 | * @return mixed Previous value |
91 | */ |
92 | public function put(string $name, $value) |
93 | { |
94 | $oldValue = $this->sessionContainer->$name ?? null; |
95 | $this->sessionContainer->$name = $value; |
96 | return $oldValue; |
97 | } |
98 | } |