- πΊπΈUnited States nicxvan
Do you have examples of the types of hooks for each?
ModuleHandler::invokeAll() contains some costly logic to recursively merge results from hook implementations.
In some cases this recursive merging is not needed, or even undesirable.
In some cases, the return value is not needed at all.
Alternative methods could be provided for these cases, promising performance improvements and an overall simpler and more predictable behavior.
These alternative methods could be part of ModuleHandler, or they could live in a separate class that depends on ModuleHandlerInterface.
The latter option would allow to introduce this change without changing the interface.
Developers could then decide which version of the method they want to call.
Example implementation:
public function invokeAllReturnNothing($hook, array $args) {
foreach ($this->moduleHandler->getImplementations($hook) as $module) {
$function = $module . '_' . $hook;
call_user_func_array($function, $args);
}
}
public function invokeAllReturnArraySum($hook, array $args = array()) {
$return = array();
foreach ($this->getImplementations($hook) as $module) {
$function = $module . '_' . $hook;
$module_result = call_user_func_array($function, $args);
if (NULL !== $module_result && is_array($module_result)) {
$return = $module_result + $return;
}
}
return $return;
}
and maybe this one for completeness..
public function invokeAllReturnKeyed($hook, array $args = array()) {
$return = array();
foreach ($this->getImplementations($hook) as $module) {
$function = $module . '_' . $hook;
$return[$module] = call_user_func_array($function, $args);
}
return $return;
}
I am sure that other optimizations could be made to ModuleHandler::invokeAll(). But this should happen in separate issues.
Active
11.0 π₯
extension system
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
Do you have examples of the types of hooks for each?