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