Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
RemoteAddressFactory
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 1
 __invoke
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3/**
4 * RemoteAddress utility factory. This uses the core Laminas RemoteAddress but
5 * configures it according to VuFind settings.
6 *
7 * PHP version 8
8 *
9 * Copyright (C) Villanova University 2019.
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  View_Helpers
26 * @author   Demian Katz <demian.katz@villanova.edu>
27 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
28 * @link     https://vufind.org/wiki/development Wiki
29 */
30
31namespace VuFind\Http\PhpEnvironment;
32
33use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
34use Laminas\ServiceManager\Exception\ServiceNotFoundException;
35use Laminas\ServiceManager\Factory\FactoryInterface;
36use Psr\Container\ContainerExceptionInterface as ContainerException;
37use Psr\Container\ContainerInterface;
38
39/**
40 * RemoteAddress utility factory.
41 *
42 * @category VuFind
43 * @package  View_Helpers
44 * @author   Demian Katz <demian.katz@villanova.edu>
45 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
46 * @link     https://vufind.org/wiki/development Wiki
47 */
48class RemoteAddressFactory implements FactoryInterface
49{
50    /**
51     * Create an object
52     *
53     * @param ContainerInterface $container     Service manager
54     * @param string             $requestedName Service being created
55     * @param null|array         $options       Extra options (optional)
56     *
57     * @return object
58     *
59     * @throws ServiceNotFoundException if unable to resolve the service.
60     * @throws ServiceNotCreatedException if an exception is raised when
61     * creating a service.
62     * @throws ContainerException&\Throwable if any other error occurs
63     */
64    public function __invoke(
65        ContainerInterface $container,
66        $requestedName,
67        array $options = null
68    ) {
69        if (!empty($options)) {
70            throw new \Exception('Unexpected options sent to factory.');
71        }
72        $cfg = $container->get(\VuFind\Config\PluginManager::class)->get('config');
73        $object = new $requestedName();
74        if ($cfg->Site->reverse_proxy ?? false) {
75            $object->setUseProxy(true);
76        }
77        return $object;
78    }
79}