prefetchForObject($object)) { $hooks[] = $hook; } } catch (Exception $e) { Logger::error('Failed to load hook %s:', get_class($hook), $e); } } return function (string $key, $value) use ($hooks, $object) { $newKey = $key; $newValue = $value; $group = null; foreach ($hooks as $hook) { /** @var self $hook */ try { $renderedKey = $hook->renderCustomVarKey($key); $renderedValue = $hook->renderCustomVarValue($key, $value); $group = $hook->identifyCustomVarGroup($key); } catch (Exception $e) { Logger::error('Failed to use hook %s:', get_class($hook), $e); continue; } if ($renderedKey !== null || $renderedValue !== null) { $newKey = $renderedKey ?? $key; $newValue = $renderedValue ?? $value; break; } } return [$newKey, $newValue, $group]; }; } }