Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
SecureDelegatorFactory | |
0.00% |
0 / 6 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
__invoke | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
delegate | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Secure session delegator factory |
5 | * |
6 | * Copyright (C) Villanova University 2018, |
7 | * Leipzig University Library <info@ub.uni-leipzig.de> 2018. |
8 | * |
9 | * PHP version 8 |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License version 2, |
13 | * as published by the Free Software Foundation. |
14 | * |
15 | * This program is distributed in the hope that it will be useful, |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | * GNU General Public License for more details. |
19 | * |
20 | * You should have received a copy of the GNU General Public License |
21 | * along with this program; if not, write to the Free Software |
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23 | * |
24 | * @category VuFind |
25 | * @package Session_Handlers |
26 | * @author Demian Katz <demian.katz@villanova.edu> |
27 | * @author Sebastian Kehr <kehr@ub.uni-leipzig.de> |
28 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
29 | * @link https://vufind.org/wiki/development:plugins:session_handlers Wiki |
30 | */ |
31 | |
32 | namespace VuFind\Session; |
33 | |
34 | use Laminas\ServiceManager\Factory\DelegatorFactoryInterface; |
35 | use Psr\Container\ContainerInterface; |
36 | |
37 | use function call_user_func; |
38 | |
39 | /** |
40 | * Secure session delegator factory |
41 | * |
42 | * @category VuFind |
43 | * @package Session_Handlers |
44 | * @author Demian Katz <demian.katz@villanova.edu> |
45 | * @author Sebastian Kehr <kehr@ub.uni-leipzig.de> |
46 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
47 | * @link https://vufind.org/wiki/development:plugins:session_handlers Wiki |
48 | */ |
49 | class SecureDelegatorFactory implements DelegatorFactoryInterface |
50 | { |
51 | /** |
52 | * Invokes this factory. |
53 | * |
54 | * @param ContainerInterface $container Service container |
55 | * @param string $name Service name |
56 | * @param callable $callback Service callback |
57 | * @param array|null $options Service options |
58 | * |
59 | * @return SecureDelegator |
60 | * |
61 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
62 | */ |
63 | public function __invoke( |
64 | ContainerInterface $container, |
65 | $name, |
66 | callable $callback, |
67 | array $options = null |
68 | ): HandlerInterface { |
69 | /** |
70 | * The wrapped session handler. |
71 | * |
72 | * @var HandlerInterface $handler |
73 | */ |
74 | $handler = call_user_func($callback); |
75 | $config = $container->get(\VuFind\Config\PluginManager::class); |
76 | $secure = $config->get('config')->Session->secure ?? false; |
77 | return $secure ? $this->delegate($container, $handler) : $handler; |
78 | } |
79 | |
80 | /** |
81 | * Creates the delegating session handler |
82 | * |
83 | * @param ContainerInterface $container Service Container |
84 | * @param HandlerInterface $handler Wrapped session handler |
85 | * |
86 | * @return HandlerInterface |
87 | */ |
88 | protected function delegate( |
89 | ContainerInterface $container, |
90 | HandlerInterface $handler |
91 | ): HandlerInterface { |
92 | $cookieManager = $container->get(\VuFind\Cookie\CookieManager::class); |
93 | return new SecureDelegator($cookieManager, $handler); |
94 | } |
95 | } |