Skip to content
Snippets Groups Projects
Commit ab6c0a0b authored by Demian Katz's avatar Demian Katz
Browse files

Refactor to allow plugin manager config keys to be looked up.

parent eb6063e2
Branches
Tags
No related merge requests found
...@@ -41,6 +41,22 @@ use Zend\ServiceManager\Factory\FactoryInterface; ...@@ -41,6 +41,22 @@ use Zend\ServiceManager\Factory\FactoryInterface;
*/ */
class AbstractPluginManagerFactory implements 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 * Create an object
* *
...@@ -61,11 +77,7 @@ class AbstractPluginManagerFactory implements FactoryInterface ...@@ -61,11 +77,7 @@ class AbstractPluginManagerFactory implements FactoryInterface
if (!empty($options)) { if (!empty($options)) {
throw new \Exception('Unexpected options sent to factory.'); throw new \Exception('Unexpected options sent to factory.');
} }
// Extract namespace of plugin manager (chop off leading top-level $configKey = $this->getConfigKey($requestedName);
// namespace -- e.g. VuFind -- and trailing PluginManager class).
$regex = '/^[^\\\\]+\\\\(.*)\\\\PluginManager$/';
preg_match($regex, $requestedName, $matches);
$configKey = strtolower(str_replace('\\', '_', $matches[1]));
if (empty($configKey)) { if (empty($configKey)) {
$error = 'Problem determining config key for ' . $requestedName; $error = 'Problem determining config key for ' . $requestedName;
throw new \Exception($error); throw new \Exception($error);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment