Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
Pazpar2BackendFactory | |
0.00% |
0 / 34 |
|
0.00% |
0 / 5 |
72 | |
0.00% |
0 / 1 |
__invoke | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
createBackend | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
createConnector | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
createQueryBuilder | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
createRecordCollectionFactory | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Factory for Pazpar2 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\Pazpar2\Backend; |
34 | use VuFindSearch\Backend\Pazpar2\Connector; |
35 | use VuFindSearch\Backend\Pazpar2\QueryBuilder; |
36 | use VuFindSearch\Backend\Pazpar2\Response\RecordCollectionFactory; |
37 | |
38 | /** |
39 | * Factory for Pazpar2 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 Pazpar2BackendFactory extends AbstractBackendFactory |
48 | { |
49 | /** |
50 | * Logger. |
51 | * |
52 | * @var \Laminas\Log\LoggerInterface |
53 | */ |
54 | protected $logger; |
55 | |
56 | /** |
57 | * VuFind configuration |
58 | * |
59 | * @var \Laminas\Config\Config |
60 | */ |
61 | protected $config; |
62 | |
63 | /** |
64 | * Create service |
65 | * |
66 | * @param ContainerInterface $sm Service manager |
67 | * @param string $name Requested service name (unused) |
68 | * @param array $options Extra options (unused) |
69 | * |
70 | * @return Backend |
71 | * |
72 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
73 | */ |
74 | public function __invoke(ContainerInterface $sm, $name, array $options = null) |
75 | { |
76 | $this->setup($sm); |
77 | $this->config = $this->serviceLocator |
78 | ->get(\VuFind\Config\PluginManager::class) |
79 | ->get('Pazpar2'); |
80 | if ($this->serviceLocator->has(\VuFind\Log\Logger::class)) { |
81 | $this->logger = $this->serviceLocator->get(\VuFind\Log\Logger::class); |
82 | } |
83 | $connector = $this->createConnector(); |
84 | $backend = $this->createBackend($connector); |
85 | return $backend; |
86 | } |
87 | |
88 | /** |
89 | * Create the Pazpar2 backend. |
90 | * |
91 | * @param Connector $connector Connector |
92 | * |
93 | * @return Backend |
94 | */ |
95 | protected function createBackend(Connector $connector) |
96 | { |
97 | $backend = new Backend($connector, $this->createRecordCollectionFactory()); |
98 | $backend->setLogger($this->logger); |
99 | $backend->setQueryBuilder($this->createQueryBuilder()); |
100 | if (isset($this->config->General->max_query_time)) { |
101 | $backend->setMaxQueryTime($this->config->General->max_query_time); |
102 | } |
103 | if (isset($this->config->General->progress_target)) { |
104 | $backend->setSearchProgressTarget( |
105 | $this->config->General->progress_target |
106 | ); |
107 | } |
108 | return $backend; |
109 | } |
110 | |
111 | /** |
112 | * Create the Pazpar2 connector. |
113 | * |
114 | * @return Connector |
115 | */ |
116 | protected function createConnector() |
117 | { |
118 | $connector = new Connector( |
119 | $this->config->General->base_url, |
120 | $this->createHttpClient() |
121 | ); |
122 | $connector->setLogger($this->logger); |
123 | return $connector; |
124 | } |
125 | |
126 | /** |
127 | * Create the Pazpar2 query builder. |
128 | * |
129 | * @return QueryBuilder |
130 | */ |
131 | protected function createQueryBuilder() |
132 | { |
133 | return new QueryBuilder(); |
134 | } |
135 | |
136 | /** |
137 | * Create the record collection factory |
138 | * |
139 | * @return RecordCollectionFactory |
140 | */ |
141 | protected function createRecordCollectionFactory() |
142 | { |
143 | $manager = $this->serviceLocator |
144 | ->get(\VuFind\RecordDriver\PluginManager::class); |
145 | $callback = function ($data) use ($manager) { |
146 | $driver = $manager->get('Pazpar2'); |
147 | $driver->setRawData($data); |
148 | return $driver; |
149 | }; |
150 | return new RecordCollectionFactory($callback); |
151 | } |
152 | } |