Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
EITBackendFactory
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 5
42
0.00% covered (danger)
0.00%
0 / 1
 __invoke
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 createBackend
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 createConnector
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
 createQueryBuilder
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 createRecordCollectionFactory
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * Factory for EBSCO Integration Toolkit (EIT) backends.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Julia Bauder 2013.
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  Search
25 * @author   Julia Bauder <bauderj@grinnell.edu>
26 * @author   David Maus <maus@hab.de>
27 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
28 * @link     https://vufind.org Main Site
29 */
30
31namespace VuFind\Search\Factory;
32
33use Psr\Container\ContainerInterface;
34use VuFindSearch\Backend\EIT\Backend;
35use VuFindSearch\Backend\EIT\Connector;
36use VuFindSearch\Backend\EIT\QueryBuilder;
37use VuFindSearch\Backend\EIT\Response\XML\RecordCollectionFactory;
38
39/**
40 * Factory for EIT backends.
41 *
42 * @category VuFind
43 * @package  Search
44 * @author   Julia Bauder <bauderj@grinnell.edu>
45 * @author   David Maus <maus@hab.de>
46 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
47 * @link     https://vufind.org Main Site
48 */
49class EITBackendFactory extends AbstractBackendFactory
50{
51    /**
52     * Logger.
53     *
54     * @var \Laminas\Log\LoggerInterface
55     */
56    protected $logger;
57
58    /**
59     * VuFind configuration
60     *
61     * @var \Laminas\Config\Config
62     */
63    protected $config;
64
65    /**
66     * Create service
67     *
68     * @param ContainerInterface $sm      Service manager
69     * @param string             $name    Requested service name (unused)
70     * @param array              $options Extra options (unused)
71     *
72     * @return Backend
73     *
74     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
75     */
76    public function __invoke(ContainerInterface $sm, $name, array $options = null)
77    {
78        $this->setup($sm);
79        $this->config = $this->serviceLocator
80            ->get(\VuFind\Config\PluginManager::class)
81            ->get('EIT');
82        if ($this->serviceLocator->has(\VuFind\Log\Logger::class)) {
83            $this->logger = $this->serviceLocator->get(\VuFind\Log\Logger::class);
84        }
85        $connector = $this->createConnector();
86        $backend   = $this->createBackend($connector);
87        return $backend;
88    }
89
90    /**
91     * Create the EIT backend.
92     *
93     * @param Connector $connector Connector
94     *
95     * @return Backend
96     */
97    protected function createBackend(Connector $connector)
98    {
99        $backend = new Backend($connector, $this->createRecordCollectionFactory());
100        $backend->setLogger($this->logger);
101        $backend->setQueryBuilder($this->createQueryBuilder());
102        return $backend;
103    }
104
105    /**
106     * Create the EIT connector.
107     *
108     * @return Connector
109     */
110    protected function createConnector()
111    {
112        $prof = $this->config->General->prof ?? null;
113        $pwd = $this->config->General->pwd ?? null;
114        $base = $this->config->General->base_url
115            ?? 'https://eit.ebscohost.com/Services/SearchService.asmx/Search';
116        $dbs = $this->config->General->dbs ?? null;
117        $connector = new Connector(
118            $base,
119            $this->createHttpClient(),
120            $prof,
121            $pwd,
122            $dbs
123        );
124        $connector->setLogger($this->logger);
125        return $connector;
126    }
127
128    /**
129     * Create the EIT query builder.
130     *
131     * @return QueryBuilder
132     */
133    protected function createQueryBuilder()
134    {
135        return new QueryBuilder();
136    }
137
138    /**
139     * Create the record collection factory
140     *
141     * @return RecordCollectionFactory
142     */
143    protected function createRecordCollectionFactory()
144    {
145        $manager = $this->serviceLocator
146            ->get(\VuFind\RecordDriver\PluginManager::class);
147        $callback = function ($data) use ($manager) {
148            $driver = $manager->get('EIT');
149            $driver->setRawData($data);
150            return $driver;
151        };
152        return new RecordCollectionFactory($callback);
153    }
154}