Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
ConfigurationBasedFactory | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | n/a |
0 / 0 |
|||
__invoke | n/a |
0 / 0 |
n/a |
0 / 0 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Hierarchy Driver Factory Class |
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 Hierarchy_Drivers |
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:hierarchy_components Wiki |
28 | */ |
29 | |
30 | namespace VuFind\Hierarchy\Driver; |
31 | |
32 | use Psr\Container\ContainerInterface; |
33 | |
34 | /** |
35 | * Hierarchy Driver Factory Class |
36 | * |
37 | * This is a factory class to build objects for managing hierarchies. |
38 | * |
39 | * @category VuFind |
40 | * @package Hierarchy_Drivers |
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:hierarchy_components Wiki |
44 | * |
45 | * @codeCoverageIgnore |
46 | */ |
47 | class ConfigurationBasedFactory |
48 | { |
49 | /** |
50 | * This constructs a hierarchy driver using VuFind's service setup. |
51 | * |
52 | * @param ContainerInterface $container Service container |
53 | * @param string $requestedName Service being built |
54 | * @param array|null $options Name of driver class |
55 | * |
56 | * @return object |
57 | * |
58 | * @throws \Exception if options is populated |
59 | */ |
60 | public function __invoke( |
61 | ContainerInterface $container, |
62 | $requestedName, |
63 | array $options = null |
64 | ) { |
65 | if (!empty($options)) { |
66 | throw new \Exception('Unexpected options passed to factory.'); |
67 | } |
68 | // Get config name from requestedName |
69 | $parts = explode('\\', $requestedName); |
70 | $config = end($parts); |
71 | // Set up options based on global VuFind settings: |
72 | $configReader = $container->get(\VuFind\Config\PluginManager::class); |
73 | $globalConfig = $configReader->get('config'); |
74 | $options = [ |
75 | 'enabled' => $globalConfig->Hierarchy->showTree ?? false, |
76 | ]; |
77 | |
78 | // Load driver-specific configuration: |
79 | $driverConfig = $configReader->get($config); |
80 | |
81 | // Build object: |
82 | return new ConfigurationBased( |
83 | $driverConfig, |
84 | $container->get(\VuFind\Hierarchy\TreeDataSource\PluginManager::class), |
85 | $container->get(\VuFind\Hierarchy\TreeRenderer\PluginManager::class), |
86 | $options |
87 | ); |
88 | } |
89 | } |