protected function initializeEnvironment(
        ProjectDescriptor $project,
        Transformation $transformation,
        string $destination
    ): Twig_Environment {
        $callingTemplatePath = $this->getTemplatePath($transformation);

        $baseTemplatesPath = $transformation->getTransformer()->getTemplates()->getTemplatesPath();

        $templateFolders = [
            $baseTemplatesPath . '/..' . DIRECTORY_SEPARATOR . $callingTemplatePath,
            // http://twig.sensiolabs.org/doc/recipes.html#overriding-a-template-that-also-extends-itself
            $baseTemplatesPath,
        ];

        // get all invoked template paths, they overrule the calling template path
        /** @var \phpDocumentor\Transformer\Template $template */
        foreach ($transformation->getTransformer()->getTemplates() as $template) {
            $path = $baseTemplatesPath . DIRECTORY_SEPARATOR . $template->getName();
            array_unshift($templateFolders, $path);
        }

        // Clone twig because otherwise we cannot re-set the extensions on this twig environment on every run of this
        // writer
        $env = clone $this->twig;
        $env->setLoader(new Twig_Loader_Filesystem($templateFolders));

        $this->addPhpDocumentorExtension($project, $transformation, $destination, $env);
        $this->addExtensionsFromTemplateConfiguration($transformation, $project, $env);

        return $env;
    }
protected function initializeEnvironment(
        ProjectDescriptor $project,
        Transformation $transformation,
        string $destination
    ): Twig_Environment {
        $callingTemplatePath = $this->getTemplatePath($transformation);

        $baseTemplatesPath = $transformation->getTransformer()->getTemplates()->getTemplatesPath();

        $templateFolders = [
            $baseTemplatesPath . '/..' . DIRECTORY_SEPARATOR . $callingTemplatePath,
            // http://twig.sensiolabs.org/doc/recipes.html#overriding-a-template-that-also-extends-itself
            $baseTemplatesPath,
        ];

        // get all invoked template paths, they overrule the calling template path
        /** @var \phpDocumentor\Transformer\Template $template */
        foreach ($transformation->getTransformer()->getTemplates() as $template) {
            $path = $baseTemplatesPath . DIRECTORY_SEPARATOR . $template->getName();
            array_unshift($templateFolders, $path);
        }

        // Clone twig because otherwise we cannot re-set the extensions on this twig environment on every run of this
        // writer
        $env = clone $this->twig;
        $env->setLoader(new Twig_Loader_Filesystem($templateFolders));

        $this->addPhpDocumentorExtension($project, $transformation, $destination, $env);
        $this->addExtensionsFromTemplateConfiguration($transformation, $project, $env);

        return $env;
    }
protected function initializeEnvironment ( ProjectDescriptor $ project , Transformation $ transformation , string $ destination ) : Twig_Environment { $ callingTemplatePath = $ this -> getTemplatePath ( $ transformation ) ; $ baseTemplatesPath = $ transformation -> getTransformer ( ) -> getTemplates ( ) -> getTemplatesPath ( ) ; $ templateFolders = [ $ baseTemplatesPath . '/..' . DIRECTORY_SEPARATOR . $ callingTemplatePath , // http://twig.sensiolabs.org/doc/recipes.html#overriding-a-template-that-also-extends-itself $ baseTemplatesPath , ] ; // get all invoked template paths, they overrule the calling template path /** @var \phpDocumentor\Transformer\Template $template */ foreach ( $ transformation -> getTransformer ( ) -> getTemplates ( ) as $ template ) { $ path = $ baseTemplatesPath . DIRECTORY_SEPARATOR . $ template -> getName ( ) ; array_unshift ( $ templateFolders , $ path ) ; } // Clone twig because otherwise we cannot re-set the extensions on this twig environment on every run of this // writer $ env = clone $ this -> twig ; $ env -> setLoader ( new Twig_Loader_Filesystem ( $ templateFolders ) ) ; $ this -> addPhpDocumentorExtension ( $ project , $ transformation , $ destination , $ env ) ; $ this -> addExtensionsFromTemplateConfiguration ( $ transformation , $ project , $ env ) ; return $ env ; }
Initializes the Twig environment with the template, base extension and additionally defined extensions.
Initializes the Twig environment with the template base extension and additionally defined extensions .