Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

TwigEngine.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 3.60 KiB


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  namespace Symfony\Bridge\Twig;
013   
014  use Symfony\Component\Templating\EngineInterface;
015  use Symfony\Component\Templating\StreamingEngineInterface;
016  use Symfony\Component\Templating\TemplateNameParserInterface;
017  use Symfony\Component\Templating\TemplateReferenceInterface;
018   
019  /**
020   * This engine knows how to render Twig templates.
021   *
022   * @author Fabien Potencier <fabien@symfony.com>
023   */
024  class TwigEngine implements EngineInterface, StreamingEngineInterface
025  {
026      protected $environment;
027      protected $parser;
028   
029      /**
030       * Constructor.
031       *
032       * @param \Twig_Environment           $environment A \Twig_Environment instance
033       * @param TemplateNameParserInterface $parser      A TemplateNameParserInterface instance
034       */
035      public function __construct(\Twig_Environment $environment, TemplateNameParserInterface $parser)
036      {
037          $this->environment = $environment;
038          $this->parser = $parser;
039      }
040   
041      /**
042       * {@inheritdoc}
043       *
044       * It also supports \Twig_Template as name parameter.
045       *
046       * @throws \Twig_Error if something went wrong like a thrown exception while rendering the template
047       */
048      public function render($name, array $parameters = array())
049      {
050          return $this->load($name)->render($parameters);
051      }
052   
053      /**
054       * {@inheritdoc}
055       *
056       * It also supports \Twig_Template as name parameter.
057       *
058       * @throws \Twig_Error if something went wrong like a thrown exception while rendering the template
059       */
060      public function stream($name, array $parameters = array())
061      {
062          $this->load($name)->display($parameters);
063      }
064   
065      /**
066       * {@inheritdoc}
067       *
068       * It also supports \Twig_Template as name parameter.
069       */
070      public function exists($name)
071      {
072          if ($name instanceof \Twig_Template) {
073              return true;
074          }
075   
076          $loader = $this->environment->getLoader();
077   
078          if ($loader instanceof \Twig_ExistsLoaderInterface) {
079              return $loader->exists((string) $name);
080          }
081   
082          try {
083              // cast possible TemplateReferenceInterface to string because the
084              // EngineInterface supports them but Twig_LoaderInterface does not
085              $loader->getSource((string) $name);
086          } catch (\Twig_Error_Loader $e) {
087              return false;
088          }
089   
090          return true;
091      }
092   
093      /**
094       * {@inheritdoc}
095       *
096       * It also supports \Twig_Template as name parameter.
097       */
098      public function supports($name)
099      {
100          if ($name instanceof \Twig_Template) {
101              return true;
102          }
103   
104          $template = $this->parser->parse($name);
105   
106          return 'twig' === $template->get('engine');
107      }
108   
109      /**
110       * Loads the given template.
111       *
112       * @param string|TemplateReferenceInterface|\Twig_Template $name A template name or an instance of
113       *                                                               TemplateReferenceInterface or \Twig_Template
114       *
115       * @return \Twig_TemplateInterface A \Twig_TemplateInterface instance
116       *
117       * @throws \InvalidArgumentException if the template does not exist
118       */
119      protected function load($name)
120      {
121          if ($name instanceof \Twig_Template) {
122              return $name;
123          }
124   
125          try {
126              return $this->environment->loadTemplate((string) $name);
127          } catch (\Twig_Error_Loader $e) {
128              throw new \InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
129          }
130      }
131  }
132