Skip to content
Snippets Groups Projects
Commit f6a0cef1 authored by nlighteneddesign's avatar nlighteneddesign
Browse files

Address comments on moduleFinder

parent e8652d41
No related branches found
No related tags found
No related merge requests found
...@@ -125,7 +125,7 @@ public function process(ContainerBuilder $container): array { ...@@ -125,7 +125,7 @@ public function process(ContainerBuilder $container): array {
// Store the implementation details for registering the hook. // Store the implementation details for registering the hook.
$implementations[$hookAttribute->hook][$hookAttribute->module][$class][$hookAttribute->method] = $hookAttribute->method; $implementations[$hookAttribute->hook][$hookAttribute->module][$class][$hookAttribute->method] = $hookAttribute->method;
// Reverse lookup for modules implementing hooks. // Reverse lookup for modules implementing hooks.
$moduleFinder[$class][$hookAttribute->method] = $hookAttribute->module; $moduleFinder[$class][$hookAttribute->method][$hookAttribute->hook] = $hookAttribute->module;
if ($hookAttribute->order) { if ($hookAttribute->order) {
$hookOrderOperations[] = $hookAttribute; $hookOrderOperations[] = $hookAttribute;
} }
...@@ -139,7 +139,7 @@ public function process(ContainerBuilder $container): array { ...@@ -139,7 +139,7 @@ public function process(ContainerBuilder $container): array {
// registration to ensure the hook it is removing has already been // registration to ensure the hook it is removing has already been
// discovered. // discovered.
foreach ($processAfter[RemoveHook::class] as $removeHook) { foreach ($processAfter[RemoveHook::class] as $removeHook) {
if ($module = ($moduleFinder[$removeHook->class][$removeHook->method] ?? '')) { if ($module = ($moduleFinder[$removeHook->class][$removeHook->method][$removeHook->hook] ?? '')) {
unset($implementations[$removeHook->hook][$module][$removeHook->class][$removeHook->method]); unset($implementations[$removeHook->hook][$module][$removeHook->class][$removeHook->method]);
// A module can implement a hook more than one time so confirm no // A module can implement a hook more than one time so confirm no
// more implementations before removing from the // more implementations before removing from the
...@@ -251,10 +251,10 @@ protected static function registerImplementations(ContainerBuilder $container, H ...@@ -251,10 +251,10 @@ protected static function registerImplementations(ContainerBuilder $container, H
* Lists of extra hooks to order together with, keyed by hook name. * Lists of extra hooks to order together with, keyed by hook name.
* @param array<string, array<string, array<class-string, list<string>>>> $implementations * @param array<string, array<string, array<class-string, list<string>>>> $implementations
* Hook implementations, as method names by hook, module and class. * Hook implementations, as method names by hook, module and class.
* @param array<class-string, array<string, string>> $moduleFinder * @param array<class-string, array<array<string, string>>> $moduleFinder
* Lookup map to find the module for each hook implementation. * Lookup map to find the module for each hook implementation.
* Array keys are the class and method of the hook implementation, array * Array keys are the class, method, and hook, array values are module
* values are module names. * names.
* The module name can be different from the module the class is in, * The module name can be different from the module the class is in,
* because an implementation can be on behalf of another module. * because an implementation can be on behalf of another module.
*/ */
...@@ -577,8 +577,9 @@ protected static function addTagToDefinition(Definition $definition, string|int ...@@ -577,8 +577,9 @@ protected static function addTagToDefinition(Definition $definition, string|int
* The container. * The container.
* @param list<array{class-string, string}> $classesAndMethods * @param list<array{class-string, string}> $classesAndMethods
* A list of class-and-method pairs. * A list of class-and-method pairs.
* @param array<class-string, array<string, string>> $moduleFinder * @param array<class-string, array<array<string, string>>> $moduleFinder
* Module names by class and method of hook implementations. * Array keys are the class, method, and hook, array values are module
* names.
* @param string $combinedHook * @param string $combinedHook
* A string made form list of hooks separated by : * A string made form list of hooks separated by :
*/ */
...@@ -588,6 +589,9 @@ protected static function registerComplexHookImplementations(ContainerBuilder $c ...@@ -588,6 +589,9 @@ protected static function registerComplexHookImplementations(ContainerBuilder $c
foreach ($classesAndMethods as [$class, $method]) { foreach ($classesAndMethods as [$class, $method]) {
// Ordering against not installed modules is possible. // Ordering against not installed modules is possible.
if (isset($moduleFinder[$class][$method])) { if (isset($moduleFinder[$class][$method])) {
if (count(array_unique($moduleFinder[$class][$method])) > 1) {
throw new \LogicException('Complex ordering can only work when all implementations on a single method are for the same module.');
}
$map[$combinedHook][$class][$method] = $moduleFinder[$class][$method]; $map[$combinedHook][$class][$method] = $moduleFinder[$class][$method];
$priority = self::addTagToDefinition($container->findDefinition($class), $combinedHook, $method, $priority); $priority = self::addTagToDefinition($container->findDefinition($class), $combinedHook, $method, $priority);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment