Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
AbstractPluginManager | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
validate | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
getExpectedInterface | n/a |
0 / 0 |
n/a |
0 / 0 |
0 |
1 | <?php |
2 | |
3 | /** |
4 | * VuFind 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 ServiceManager |
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 Wiki |
28 | */ |
29 | |
30 | namespace VuFind\ServiceManager; |
31 | |
32 | use Laminas\ServiceManager\AbstractPluginManager as Base; |
33 | use Laminas\ServiceManager\Exception\InvalidServiceException; |
34 | |
35 | /** |
36 | * VuFind Plugin Manager |
37 | * |
38 | * @category VuFind |
39 | * @package ServiceManager |
40 | * @author Demian Katz <demian.katz@villanova.edu> |
41 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
42 | * @link https://vufind.org/wiki/development Wiki |
43 | * |
44 | * @SuppressWarnings(PHPMD.NumberOfChildren) |
45 | */ |
46 | abstract class AbstractPluginManager extends Base |
47 | { |
48 | use LowerCaseServiceNameTrait; |
49 | |
50 | /** |
51 | * Constructor |
52 | * |
53 | * Make sure plugins are properly initialized. |
54 | * |
55 | * @param mixed $configOrContainerInstance Configuration or container instance |
56 | * @param array $v3config If $configOrContainerInstance is a |
57 | * container, this value will be passed to the parent constructor. |
58 | */ |
59 | public function __construct( |
60 | $configOrContainerInstance = null, |
61 | array $v3config = [] |
62 | ) { |
63 | parent::__construct($configOrContainerInstance, $v3config); |
64 | $this->addInitializer( |
65 | \VuFind\ServiceManager\ServiceInitializer::class |
66 | ); |
67 | } |
68 | |
69 | /** |
70 | * Validate the plugin |
71 | * |
72 | * Checks that the filter loaded is either a valid callback or an instance |
73 | * of FilterInterface. |
74 | * |
75 | * @param mixed $plugin Plugin to validate |
76 | * |
77 | * @throws InvalidServiceException if invalid |
78 | * @return void |
79 | */ |
80 | public function validate($plugin) |
81 | { |
82 | $expectedInterface = $this->getExpectedInterface(); |
83 | if (!$plugin instanceof $expectedInterface) { |
84 | throw new InvalidServiceException( |
85 | 'Plugin ' . $plugin::class . ' does not belong to ' |
86 | . $expectedInterface |
87 | ); |
88 | } |
89 | } |
90 | |
91 | /** |
92 | * Return the name of the base class or interface that plug-ins must conform |
93 | * to. |
94 | * |
95 | * @return string |
96 | */ |
97 | abstract protected function getExpectedInterface(); |
98 | } |