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

Add delegator factory support to generator.

parent c4a59565
No related merge requests found
...@@ -82,6 +82,7 @@ class GeneratorTools ...@@ -82,6 +82,7 @@ class GeneratorTools
// service or a class in a plugin manager. // service or a class in a plugin manager.
$cm = $container->get('ControllerManager'); $cm = $container->get('ControllerManager');
$cpm = $container->get('ControllerPluginManager'); $cpm = $container->get('ControllerPluginManager');
$delegators = [];
if ($container->has($class)) { if ($container->has($class)) {
$factory = $this->getFactoryFromContainer($container, $class); $factory = $this->getFactoryFromContainer($container, $class);
$configPath = ['service_manager']; $configPath = ['service_manager'];
...@@ -94,6 +95,7 @@ class GeneratorTools ...@@ -94,6 +95,7 @@ class GeneratorTools
$pmKey = $apmFactory->getConfigKey(get_class($pm)); $pmKey = $apmFactory->getConfigKey(get_class($pm));
$factory = $this->getFactoryFromContainer($pm, $class); $factory = $this->getFactoryFromContainer($pm, $class);
$configPath = ['vufind', 'plugin_managers', $pmKey]; $configPath = ['vufind', 'plugin_managers', $pmKey];
$delegators = $this->getDelegatorsFromContainer($pm, $class);
} }
// No factory found? Throw an error! // No factory found? Throw an error!
...@@ -106,8 +108,7 @@ class GeneratorTools ...@@ -106,8 +108,7 @@ class GeneratorTools
// Create the custom factory only if requested. // Create the custom factory only if requested.
$newFactory = $extendFactory $newFactory = $extendFactory
? $this->cloneFactory($factory, $target) ? $this->cloneFactory($factory, $target) : $factory;
: $factory;
// Finalize the local module configuration -- create a factory for the // Finalize the local module configuration -- create a factory for the
// new class, and set up the new class as an alias for the old class. // new class, and set up the new class as an alias for the old class.
...@@ -118,6 +119,17 @@ class GeneratorTools ...@@ -118,6 +119,17 @@ class GeneratorTools
// write operation is sufficient. // write operation is sufficient.
$this->writeNewConfig($aliasPath, $newClass, $target, false); $this->writeNewConfig($aliasPath, $newClass, $target, false);
// Clone/configure delegator factories as needed.
if (!empty($delegators)) {
$newDelegators = [];
foreach ($delegators as $delegator) {
$newDelegators[] = $extendFactory
? $this->cloneFactory($delegator, $target) : $delegator;
}
$delegatorPath = array_merge($configPath, ['delegators', $newClass]);
$this->writeNewConfig($delegatorPath, $newDelegators, $target, false);
}
return true; return true;
} }
...@@ -150,6 +162,36 @@ class GeneratorTools ...@@ -150,6 +162,36 @@ class GeneratorTools
return $factories[$class] ?? null; return $factories[$class] ?? null;
} }
/**
* Get a list of delegators in the provided container.
*
* @param ContainerInterface $container Container to inspect
*
* @return array
*/
protected function getAllDelegatorsFromContainer(ContainerInterface $container)
{
// There is no "getDelegators" method, so we need to use reflection:
$reflectionProperty = new \ReflectionProperty($container, 'delegators');
$reflectionProperty->setAccessible(true);
return $reflectionProperty->getValue($container);
}
/**
* Get delegators from the provided container (or empty array if undefined).
*
* @param ContainerInterface $container Container to inspect
* @param string $class Class whose delegators we want
*
* @return array
*/
protected function getDelegatorsFromContainer(ContainerInterface $container,
$class
) {
$delegators = $this->getAllDelegatorsFromContainer($container);
return $delegators[$class] ?? [];
}
/** /**
* Search all plugin managers for one containing the requested class (or return * Search all plugin managers for one containing the requested class (or return
* null if none found). * null if none found).
......
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