From ab6c0a0bc865349e6f95ee5639ed938276aa0296 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Tue, 6 Feb 2018 16:04:52 -0500 Subject: [PATCH] Refactor to allow plugin manager config keys to be looked up. --- .../AbstractPluginManagerFactory.php | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManagerFactory.php b/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManagerFactory.php index a4f095c1713..10dc9f2a9e9 100644 --- a/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManagerFactory.php +++ b/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManagerFactory.php @@ -41,6 +41,22 @@ use Zend\ServiceManager\Factory\FactoryInterface; */ class AbstractPluginManagerFactory implements FactoryInterface { + /** + * Determine the configuration key for the specified class name. + * + * @param string $requestedName Service being created + * + * @return string + */ + public function getConfigKey($requestedName) + { + // Extract namespace of plugin manager (chop off leading top-level + // namespace -- e.g. VuFind -- and trailing PluginManager class). + $regex = '/^[^\\\\]+\\\\(.*)\\\\PluginManager$/'; + preg_match($regex, $requestedName, $matches); + return strtolower(str_replace('\\', '_', $matches[1])); + } + /** * Create an object * @@ -61,11 +77,7 @@ class AbstractPluginManagerFactory implements FactoryInterface if (!empty($options)) { throw new \Exception('Unexpected options sent to factory.'); } - // Extract namespace of plugin manager (chop off leading top-level - // namespace -- e.g. VuFind -- and trailing PluginManager class). - $regex = '/^[^\\\\]+\\\\(.*)\\\\PluginManager$/'; - preg_match($regex, $requestedName, $matches); - $configKey = strtolower(str_replace('\\', '_', $matches[1])); + $configKey = $this->getConfigKey($requestedName); if (empty($configKey)) { $error = 'Problem determining config key for ' . $requestedName; throw new \Exception($error); -- GitLab