Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 75 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
EdsBackendFactory | |
0.00% |
0 / 75 |
|
0.00% |
0 / 8 |
182 | |
0.00% |
0 / 1 |
getServiceName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__invoke | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
createBackend | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
2 | |||
createConnector | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
6 | |||
createConnectorOptions | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
createQueryBuilder | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
createRecordCollectionFactory | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
createListeners | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | /** |
4 | * Factory for EDS backends. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 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 David Maus <maus@hab.de> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org Main Site |
28 | */ |
29 | |
30 | namespace VuFind\Search\Factory; |
31 | |
32 | use Psr\Container\ContainerInterface; |
33 | use VuFindSearch\Backend\EDS\Backend; |
34 | use VuFindSearch\Backend\EDS\Connector; |
35 | use VuFindSearch\Backend\EDS\QueryBuilder; |
36 | use VuFindSearch\Backend\EDS\Response\RecordCollectionFactory; |
37 | |
38 | /** |
39 | * Factory for EDS backends. |
40 | * |
41 | * @category VuFind |
42 | * @package Search |
43 | * @author David Maus <maus@hab.de> |
44 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
45 | * @link https://vufind.org Main Site |
46 | */ |
47 | class EdsBackendFactory extends AbstractBackendFactory |
48 | { |
49 | use SharedListenersTrait; |
50 | |
51 | /** |
52 | * Logger. |
53 | * |
54 | * @var \Laminas\Log\LoggerInterface |
55 | */ |
56 | protected $logger = null; |
57 | |
58 | /** |
59 | * EDS configuration |
60 | * |
61 | * @var \Laminas\Config\Config |
62 | */ |
63 | protected $edsConfig; |
64 | |
65 | /** |
66 | * EDS Account data |
67 | * |
68 | * @var array |
69 | */ |
70 | protected $accountData; |
71 | |
72 | /** |
73 | * Default URL for the EDS Backend. Set here for the EDS API. |
74 | * |
75 | * @var str |
76 | */ |
77 | protected $defaultApiUrl = 'https://eds-api.ebscohost.com/edsapi/rest'; |
78 | |
79 | /** |
80 | * Get the service name. This is used for both configuration |
81 | * and record driver retrieval. |
82 | * |
83 | * @return str |
84 | */ |
85 | protected function getServiceName() |
86 | { |
87 | return 'EDS'; |
88 | } |
89 | |
90 | /** |
91 | * Create service |
92 | * |
93 | * @param ContainerInterface $sm Service manager |
94 | * @param string $name Requested service name (unused) |
95 | * @param array $options Extra options (unused) |
96 | * |
97 | * @return Backend |
98 | * |
99 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
100 | */ |
101 | public function __invoke(ContainerInterface $sm, $name, array $options = null) |
102 | { |
103 | $this->setup($sm); |
104 | $this->edsConfig = $this->serviceLocator |
105 | ->get(\VuFind\Config\PluginManager::class) |
106 | ->get($this->getServiceName()); |
107 | if ($this->serviceLocator->has(\VuFind\Log\Logger::class)) { |
108 | $this->logger = $this->serviceLocator->get(\VuFind\Log\Logger::class); |
109 | } |
110 | $connector = $this->createConnector(); |
111 | $backend = $this->createBackend($connector); |
112 | $this->createListeners($backend); |
113 | return $backend; |
114 | } |
115 | |
116 | /** |
117 | * Create the EDS backend. |
118 | * |
119 | * @param Connector $connector Connector |
120 | * |
121 | * @return Backend |
122 | */ |
123 | protected function createBackend(Connector $connector) |
124 | { |
125 | $auth = $this->serviceLocator |
126 | ->get(\LmcRbacMvc\Service\AuthorizationService::class); |
127 | $isGuest = !$auth->isGranted('access.EDSExtendedResults'); |
128 | $session = new \Laminas\Session\Container( |
129 | 'EBSCO', |
130 | $this->serviceLocator->get(\Laminas\Session\SessionManager::class) |
131 | ); |
132 | $backend = new Backend( |
133 | $connector, |
134 | $this->createRecordCollectionFactory(), |
135 | $this->serviceLocator->get(\VuFind\Cache\Manager::class) |
136 | ->getCache('object'), |
137 | $session, |
138 | $this->edsConfig, |
139 | $isGuest |
140 | ); |
141 | $backend->setAuthManager( |
142 | $this->serviceLocator->get(\VuFind\Auth\Manager::class) |
143 | ); |
144 | $backend->setLogger($this->logger); |
145 | $backend->setQueryBuilder($this->createQueryBuilder()); |
146 | $backend->setBackendType($this->getServiceName()); |
147 | return $backend; |
148 | } |
149 | |
150 | /** |
151 | * Create the EDS connector. |
152 | * |
153 | * @return Connector |
154 | */ |
155 | protected function createConnector() |
156 | { |
157 | $options = $this->createConnectorOptions(); |
158 | $httpOptions = [ |
159 | 'sslverifypeer' |
160 | => (bool)($this->edsConfig->General->sslverifypeer ?? true), |
161 | ]; |
162 | $connector = new Connector( |
163 | $options, |
164 | $this->createHttpClient( |
165 | $this->edsConfig->General->timeout ?? 120, |
166 | $httpOptions |
167 | ) |
168 | ); |
169 | $connector->setLogger($this->logger); |
170 | if ($cache = $this->createConnectorCache($this->edsConfig)) { |
171 | $connector->setCache($cache); |
172 | } |
173 | return $connector; |
174 | } |
175 | |
176 | /** |
177 | * Create the options array for the EDS connector. |
178 | * |
179 | * @return array |
180 | */ |
181 | protected function createConnectorOptions() |
182 | { |
183 | $options = [ |
184 | 'search_http_method' => $this->edsConfig->General->search_http_method |
185 | ?? 'POST', |
186 | 'api_url' => $this->edsConfig->General->api_url |
187 | ?? $this->defaultApiUrl, |
188 | ]; |
189 | if (isset($this->edsConfig->General->auth_url)) { |
190 | $options['auth_url'] = $this->edsConfig->General->auth_url; |
191 | } |
192 | if (isset($this->edsConfig->General->session_url)) { |
193 | $options['session_url'] = $this->edsConfig->General->session_url; |
194 | } |
195 | return $options; |
196 | } |
197 | |
198 | /** |
199 | * Create the EDS query builder. |
200 | * |
201 | * @return QueryBuilder |
202 | */ |
203 | protected function createQueryBuilder() |
204 | { |
205 | $builder = new QueryBuilder(); |
206 | return $builder; |
207 | } |
208 | |
209 | /** |
210 | * Create the record collection factory |
211 | * |
212 | * @return RecordCollectionFactory |
213 | */ |
214 | protected function createRecordCollectionFactory() |
215 | { |
216 | $manager = $this->serviceLocator |
217 | ->get(\VuFind\RecordDriver\PluginManager::class); |
218 | $callback = function ($data) use ($manager) { |
219 | $driver = $manager->get($this->getServiceName()); |
220 | $driver->setRawData($data); |
221 | return $driver; |
222 | }; |
223 | return new RecordCollectionFactory($callback); |
224 | } |
225 | |
226 | /** |
227 | * Create listeners. |
228 | * |
229 | * @param Backend $backend Backend |
230 | * |
231 | * @return void |
232 | */ |
233 | protected function createListeners(Backend $backend) |
234 | { |
235 | $events = $this->serviceLocator->get('SharedEventManager'); |
236 | |
237 | // Attach hide facet value listener: |
238 | $hfvListener = $this->getHideFacetValueListener($backend, $this->edsConfig); |
239 | if ($hfvListener) { |
240 | $hfvListener->attach($events); |
241 | } |
242 | } |
243 | } |