Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
SessionCsrfFactory | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | n/a |
0 / 0 |
|||
__invoke | n/a |
0 / 0 |
n/a |
0 / 0 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * CSRF Validator factory. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2014. |
9 | * Copyright (C) The National Library of Finland 2018. |
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 Validator |
26 | * @author Demian Katz <demian.katz@villanova.edu> |
27 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
28 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
29 | * @link https://vufind.org/wiki/development Wiki |
30 | */ |
31 | |
32 | namespace VuFind\Validator; |
33 | |
34 | use Laminas\ServiceManager\Exception\ServiceNotCreatedException; |
35 | use Laminas\ServiceManager\Exception\ServiceNotFoundException; |
36 | use Laminas\ServiceManager\Factory\FactoryInterface; |
37 | use Psr\Container\ContainerExceptionInterface as ContainerException; |
38 | use Psr\Container\ContainerInterface; |
39 | |
40 | /** |
41 | * CSRF Validator factory. |
42 | * |
43 | * @category VuFind |
44 | * @package Validator |
45 | * @author Demian Katz <demian.katz@villanova.edu> |
46 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
47 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
48 | * @link https://vufind.org/wiki/development Wiki |
49 | * |
50 | * @codeCoverageIgnore |
51 | */ |
52 | class SessionCsrfFactory implements FactoryInterface |
53 | { |
54 | /** |
55 | * Create an object |
56 | * |
57 | * @param ContainerInterface $container Service manager |
58 | * @param string $requestedName Service being created |
59 | * @param null|array $options Extra options (optional) |
60 | * |
61 | * @return object |
62 | * |
63 | * @throws ServiceNotFoundException if unable to resolve the service. |
64 | * @throws ServiceNotCreatedException if an exception is raised when |
65 | * creating a service. |
66 | * @throws ContainerException&\Throwable if any other error occurs |
67 | */ |
68 | public function __invoke( |
69 | ContainerInterface $container, |
70 | $requestedName, |
71 | array $options = null |
72 | ) { |
73 | if (!empty($options)) { |
74 | throw new \Exception('Unexpected options passed to factory.'); |
75 | } |
76 | $config = $container->get(\VuFind\Config\PluginManager::class) |
77 | ->get('config'); |
78 | $sessionManager = $container->get(\Laminas\Session\SessionManager::class); |
79 | return new $requestedName( |
80 | [ |
81 | 'session' => new \Laminas\Session\Container('csrf', $sessionManager), |
82 | 'salt' => $config->Security->HMACkey ?? 'VuFindCsrfSalt', |
83 | ] |
84 | ); |
85 | } |
86 | } |