public function getSourceAsPath(): string
    {
        // externally loaded templates set this parameter so that template
        // resources may be placed in the same folder as the template.
        if ($this->getParameter('template_path') !== null) {
            $path = rtrim($this->getParameter('template_path')->getValue(), '/\\');
            if (file_exists($path . DIRECTORY_SEPARATOR . $this->source)) {
                return $path . DIRECTORY_SEPARATOR . $this->source;
            }
        }

        // counter a BC break that we introduced in 2.0 stable; we removed the notion of global assets
        // to be able to provide composer integration
        // TODO: remove in version 3.0
        if (strpos($this->source, 'templates/') !== 0) {
            $this->source = 'templates/abstract/' . $this->source;
            trigger_error(
                'Using shared assets in a template is deprecated and will be removed in version 3.0',
                E_USER_DEPRECATED
            );
        }

        // check whether the file exists in the phpDocumentor project directory.
        if (file_exists(__DIR__ . '/../../../' . $this->source)) {
            return __DIR__ . '/../../../' . $this->source;
        }

        // in case of a composer installation
        if (file_exists(__DIR__ . '/../../../../templates')) {
            return __DIR__ . '/../../../../' . $this->source;
        }

        // TODO: replace this as it breaks the component stuff
        // we should ditch the idea of a global set of files to fetch and have
        // a variable / injection for the global templates folder and inject
        // that here.
        $file = __DIR__ . '/../../../data/' . $this->source;

        if (!file_exists($file)) {
            throw new Exception('The source path does not exist: ' . $file);
        }

        return $file;
    }