Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
Factory | n/a |
0 / 0 |
n/a |
0 / 0 |
5 | n/a |
0 / 0 |
|||
getConfigSettingName | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | |||||
getPluginManagerServiceName | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
__invoke | n/a |
0 / 0 |
n/a |
0 / 0 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Factory for instantiating content loaders |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2009. |
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 Content |
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\Content; |
31 | |
32 | use Laminas\ServiceManager\Exception\ServiceNotCreatedException; |
33 | use Laminas\ServiceManager\Exception\ServiceNotFoundException; |
34 | use Psr\Container\ContainerExceptionInterface as ContainerException; |
35 | use Psr\Container\ContainerInterface; |
36 | |
37 | /** |
38 | * Factory for instantiating content loaders |
39 | * |
40 | * @category VuFind |
41 | * @package Content |
42 | * @author Demian Katz <demian.katz@villanova.edu> |
43 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
44 | * @link https://vufind.org/wiki/development Wiki |
45 | * |
46 | * @codeCoverageIgnore |
47 | */ |
48 | class Factory implements \Laminas\ServiceManager\Factory\FactoryInterface |
49 | { |
50 | /** |
51 | * Get the configuration setting name to get content provider settings. |
52 | * |
53 | * @param string $name Requested service name |
54 | * |
55 | * @return string |
56 | */ |
57 | protected function getConfigSettingName($name) |
58 | { |
59 | // Account for one special exception: |
60 | $lcName = strtolower($name); |
61 | return $lcName === 'authornotes' ? 'authorNotes' : $lcName; |
62 | } |
63 | |
64 | /** |
65 | * Get the plugin manager service name to build a content provider service. |
66 | * |
67 | * @param string $name Requested service name |
68 | * |
69 | * @return string |
70 | */ |
71 | protected function getPluginManagerServiceName($name) |
72 | { |
73 | $lcName = strtolower($name); |
74 | // Account for two special legacy exceptions: |
75 | $exceptions = ['authornotes' => 'AuthorNotes', 'toc' => 'TOC']; |
76 | $formattedName = $exceptions[$lcName] ?? ucfirst($lcName); |
77 | return 'VuFind\Content\\' . $formattedName . '\PluginManager'; |
78 | } |
79 | |
80 | /** |
81 | * Create an object |
82 | * |
83 | * @param ContainerInterface $container Service manager |
84 | * @param string $requestedName Service being created |
85 | * @param null|array $options Extra options (optional) |
86 | * |
87 | * @return object |
88 | * |
89 | * @throws ServiceNotFoundException if unable to resolve the service. |
90 | * @throws ServiceNotCreatedException if an exception is raised when |
91 | * creating a service. |
92 | * @throws ContainerException&\Throwable if any other error occurs |
93 | * |
94 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
95 | */ |
96 | public function __invoke( |
97 | ContainerInterface $container, |
98 | $requestedName, |
99 | array $options = null |
100 | ) { |
101 | if (!empty($options)) { |
102 | throw new \Exception('Unexpected options passed to factory.'); |
103 | } |
104 | $pm = $container->get($this->getPluginManagerServiceName($requestedName)); |
105 | $config = $container->get(\VuFind\Config\PluginManager::class) |
106 | ->get('config'); |
107 | $setting = $this->getConfigSettingName($requestedName); |
108 | $providers = $config->Content->$setting ?? ''; |
109 | return new Loader($pm, $providers); |
110 | } |
111 | } |