private function mergeParams(string $name, $vars)
    {
        $globalDefaults = isset($this->defaultParams[TemplateRendererInterface::TEMPLATE_ALL])
            ? $this->defaultParams[TemplateRendererInterface::TEMPLATE_ALL]
            : [];

        $templateDefaults = isset($this->defaultParams[$name])
            ? $this->defaultParams[$name]
            : [];

        $defaults = ArrayUtils::merge($globalDefaults, $templateDefaults);

        foreach (array_reverse($this->paramListeners) as $listener) {
            $result = $listener($vars, $defaults);
            if (null !== $result && ! is_scalar($result)) {
                return $result;
            }
        }

        return $vars;
    }