Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
94.74% |
18 / 19 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
PluginManager | |
94.74% |
18 / 19 |
|
80.00% |
4 / 5 |
10.01 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
5 | |||
getExpectedInterface | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getSolrRecord | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
2 | |||
getSearch2Record | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSolrAuthRecord | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * Record driver plugin manager |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2010. |
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 RecordDrivers |
25 | * @author Demian Katz <demian.katz@villanova.edu> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org/wiki/development:plugins:record_drivers Wiki |
28 | */ |
29 | |
30 | namespace VuFind\RecordDriver; |
31 | |
32 | use Laminas\ServiceManager\Factory\InvokableFactory; |
33 | |
34 | use function is_callable; |
35 | |
36 | /** |
37 | * Record driver plugin manager |
38 | * |
39 | * @category VuFind |
40 | * @package RecordDrivers |
41 | * @author Demian Katz <demian.katz@villanova.edu> |
42 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
43 | * @link https://vufind.org/wiki/development:plugins:record_drivers Wiki |
44 | */ |
45 | class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager |
46 | { |
47 | /** |
48 | * Default plugin aliases. |
49 | * |
50 | * @var array |
51 | */ |
52 | protected $aliases = [ |
53 | 'browzine' => BrowZine::class, |
54 | 'eds' => EDS::class, |
55 | 'eit' => EIT::class, |
56 | 'epf' => EPF::class, |
57 | 'libguides' => LibGuides::class, |
58 | 'libguidesaz' => LibGuidesAZ::class, |
59 | 'missing' => Missing::class, |
60 | 'pazpar2' => Pazpar2::class, |
61 | 'primo' => Primo::class, |
62 | 'search2default' => Search2Default::class, |
63 | 'solrarchivesspace' => SolrArchivesSpace::class, |
64 | 'solrauth' => SolrAuthMarc::class, // legacy name |
65 | 'solrauthdefault' => SolrAuthDefault::class, |
66 | 'solrauthmarc' => SolrAuthMarc::class, |
67 | 'solrdefault' => SolrDefault::class, |
68 | 'solrmarc' => SolrMarc::class, |
69 | 'solrmarcremote' => SolrMarcRemote::class, |
70 | 'solroverdrive' => SolrOverdrive::class, |
71 | 'solrreserves' => SolrReserves::class, |
72 | 'solrweb' => SolrWeb::class, |
73 | 'summon' => Summon::class, |
74 | 'worldcat' => WorldCat::class, |
75 | ]; |
76 | |
77 | /** |
78 | * Default delegator factories. |
79 | * |
80 | * @var string[][]|\Laminas\ServiceManager\Factory\DelegatorFactoryInterface[][] |
81 | */ |
82 | protected $delegators = [ |
83 | SolrMarc::class => [IlsAwareDelegatorFactory::class], |
84 | SolrMarcRemote::class => [IlsAwareDelegatorFactory::class], |
85 | ]; |
86 | |
87 | /** |
88 | * Default plugin factories. |
89 | * |
90 | * @var array |
91 | */ |
92 | protected $factories = [ |
93 | BrowZine::class => InvokableFactory::class, |
94 | EDS::class => NameBasedConfigFactory::class, |
95 | EIT::class => NameBasedConfigFactory::class, |
96 | EPF::class => NameBasedConfigFactory::class, |
97 | LibGuides::class => InvokableFactory::class, |
98 | LibGuidesAZ::class => InvokableFactory::class, |
99 | Missing::class => AbstractBaseFactory::class, |
100 | Pazpar2::class => NameBasedConfigFactory::class, |
101 | Primo::class => NameBasedConfigFactory::class, |
102 | Search2Default::class => Search2DefaultFactory::class, |
103 | SolrArchivesSpace::class => SolrDefaultFactory::class, |
104 | SolrAuthDefault::class => SolrDefaultWithoutSearchServiceFactory::class, |
105 | SolrAuthMarc::class => SolrDefaultWithoutSearchServiceFactory::class, |
106 | SolrDefault::class => SolrDefaultFactory::class, |
107 | SolrMarc::class => SolrDefaultFactory::class, |
108 | SolrMarcRemote::class => SolrDefaultFactory::class, |
109 | SolrOverdrive::class => SolrOverdriveFactory::class, |
110 | SolrReserves::class => SolrDefaultWithoutSearchServiceFactory::class, |
111 | SolrWeb::class => SolrWebFactory::class, |
112 | Summon::class => SummonFactory::class, |
113 | WorldCat::class => NameBasedConfigFactory::class, |
114 | ]; |
115 | |
116 | /** |
117 | * Constructor |
118 | * |
119 | * Make sure plugins are properly initialized. |
120 | * |
121 | * @param mixed $configOrContainerInstance Configuration or container instance |
122 | * @param array $v3config If $configOrContainerInstance is a |
123 | * container, this value will be passed to the parent constructor. |
124 | */ |
125 | public function __construct( |
126 | $configOrContainerInstance = null, |
127 | array $v3config = [] |
128 | ) { |
129 | // These objects are not meant to be shared -- every time we retrieve one, |
130 | // we are building a brand new object. |
131 | $this->sharedByDefault = false; |
132 | |
133 | $this->addAbstractFactory(PluginFactory::class); |
134 | |
135 | parent::__construct($configOrContainerInstance, $v3config); |
136 | |
137 | // Add an initializer for setting up hierarchies |
138 | $initializer = function ($sm, $instance) { |
139 | $hasHierarchyType = is_callable([$instance, 'getHierarchyType']); |
140 | if ( |
141 | $hasHierarchyType |
142 | && is_callable([$instance, 'setHierarchyDriverManager']) |
143 | ) { |
144 | if ($sm && $sm->has(\VuFind\Hierarchy\Driver\PluginManager::class)) { |
145 | $instance->setHierarchyDriverManager( |
146 | $sm->get(\VuFind\Hierarchy\Driver\PluginManager::class) |
147 | ); |
148 | } |
149 | } |
150 | }; |
151 | $this->addInitializer($initializer); |
152 | } |
153 | |
154 | /** |
155 | * Return the name of the base class or interface that plug-ins must conform |
156 | * to. |
157 | * |
158 | * @return string |
159 | */ |
160 | protected function getExpectedInterface() |
161 | { |
162 | return AbstractBase::class; |
163 | } |
164 | |
165 | /** |
166 | * Convenience method to retrieve a populated Solr record driver. |
167 | * |
168 | * @param array $data Raw Solr data |
169 | * @param string $keyPrefix Record class name prefix |
170 | * @param string $defaultKeySuffix Default key suffix |
171 | * |
172 | * @return AbstractBase |
173 | */ |
174 | public function getSolrRecord( |
175 | $data, |
176 | $keyPrefix = 'Solr', |
177 | $defaultKeySuffix = 'Default' |
178 | ) { |
179 | $key = $keyPrefix . ucwords( |
180 | $data['record_format'] ?? $data['recordtype'] ?? $defaultKeySuffix |
181 | ); |
182 | $recordType = $this->has($key) ? $key : $keyPrefix . $defaultKeySuffix; |
183 | |
184 | // Extract highlighting details injected earlier by |
185 | // \VuFindSearch\Backend\Solr\Response\Json\RecordCollectionFactory |
186 | $hl = $data['__highlight_details'] ?? []; |
187 | unset($data['__highlight_details']); |
188 | // Build the object: |
189 | $driver = $this->get($recordType); |
190 | $driver->setRawData($data); |
191 | $driver->setHighlightDetails($hl); |
192 | return $driver; |
193 | } |
194 | |
195 | /** |
196 | * Convenience method to retrieve a populated Search2 record driver. |
197 | * |
198 | * @param array $data Raw Solr data |
199 | * @param string $defaultKeySuffix Default key suffix |
200 | * |
201 | * @return AbstractBase |
202 | */ |
203 | public function getSearch2Record($data, $defaultKeySuffix = 'Default') |
204 | { |
205 | return $this->getSolrRecord($data, 'Search2', $defaultKeySuffix); |
206 | } |
207 | |
208 | /** |
209 | * Convenience method to retrieve a populated Solr authority record driver. |
210 | * |
211 | * @param array $data Raw Solr data |
212 | * |
213 | * @return AbstractBase |
214 | */ |
215 | public function getSolrAuthRecord($data) |
216 | { |
217 | return $this->getSolrRecord($data, 'SolrAuth'); |
218 | } |
219 | } |