Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
LoginTokenManagerFactory | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
__invoke | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 | |||
getBrowscap | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Factory for Login token authentication |
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 Authentication |
25 | * @author Jaro Ravila <jaro.ravila@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\Auth; |
31 | |
32 | use BrowscapPHP\Browscap; |
33 | use Laminas\Cache\Psr\SimpleCache\SimpleCacheDecorator; |
34 | use Laminas\Log\PsrLoggerAdapter; |
35 | use Laminas\ServiceManager\Exception\ServiceNotCreatedException; |
36 | use Laminas\ServiceManager\Exception\ServiceNotFoundException; |
37 | use Psr\Container\ContainerExceptionInterface as ContainerException; |
38 | use Psr\Container\ContainerInterface; |
39 | use VuFind\Db\Service\LoginTokenServiceInterface; |
40 | use VuFind\Db\Service\UserServiceInterface; |
41 | |
42 | /** |
43 | * Factory for login token authentication |
44 | * |
45 | * @category VuFind |
46 | * @package Authentication |
47 | * @author Jaro Ravila <jaro.ravila@helsinki.fi> |
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 LoginTokenManagerFactory implements \Laminas\ServiceManager\Factory\FactoryInterface |
52 | { |
53 | /** |
54 | * Service manager |
55 | * |
56 | * @var ContainerInterface |
57 | */ |
58 | protected $container; |
59 | |
60 | /** |
61 | * Create an object |
62 | * |
63 | * @param ContainerInterface $container Service manager |
64 | * @param string $requestedName Service being created |
65 | * @param null|array $options Extra options (optional) |
66 | * |
67 | * @return object |
68 | * |
69 | * @throws ServiceNotFoundException if unable to resolve the service. |
70 | * @throws ServiceNotCreatedException if an exception is raised when |
71 | * creating a service. |
72 | * @throws ContainerException&\Throwable if any other error occurs |
73 | */ |
74 | public function __invoke( |
75 | ContainerInterface $container, |
76 | $requestedName, |
77 | array $options = null |
78 | ) { |
79 | if (!empty($options)) { |
80 | throw new \Exception('Unexpected options sent to factory.'); |
81 | } |
82 | $this->container = $container; |
83 | |
84 | $dbServiceManager = $container->get(\VuFind\Db\Service\PluginManager::class); |
85 | return new $requestedName( |
86 | $container->get(\VuFind\Config\PluginManager::class)->get('config'), |
87 | $dbServiceManager->get(UserServiceInterface::class), |
88 | $dbServiceManager->get(LoginTokenServiceInterface::class), |
89 | $container->get(\VuFind\Cookie\CookieManager::class), |
90 | $container->get(\Laminas\Session\SessionManager::class), |
91 | $container->get(\VuFind\Mailer\Mailer::class), |
92 | $container->get('ViewRenderer'), |
93 | [$this, 'getBrowscap'] |
94 | ); |
95 | } |
96 | |
97 | /** |
98 | * Create a Browscap instance |
99 | * |
100 | * @return Browscap |
101 | */ |
102 | public function getBrowscap(): Browscap |
103 | { |
104 | $cache = new SimpleCacheDecorator($this->container->get(\VuFind\Cache\Manager::class)->getCache('browscap')); |
105 | $logger = new PsrLoggerAdapter($this->container->get(\VuFind\Log\Logger::class)); |
106 | return new Browscap($cache, $logger); |
107 | } |
108 | } |