Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
TwigEngine.php
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 use Twig\Environment;
019 use Twig\Error\Error;
020 use Twig\Error\LoaderError;
021 use Twig\Loader\ExistsLoaderInterface;
022 use Twig\Loader\SourceContextLoaderInterface;
023 use Twig\Template;
024
025 /**
026 * This engine knows how to render Twig templates.
027 *
028 * @author Fabien Potencier <fabien@symfony.com>
029 */
030 class TwigEngine implements EngineInterface, StreamingEngineInterface
031 {
032 protected $environment;
033 protected $parser;
034
035 public function __construct(Environment $environment, TemplateNameParserInterface $parser)
036 {
037 $this->environment = $environment;
038 $this->parser = $parser;
039 }
040
041 /**
042 * {@inheritdoc}
043 *
044 * It also supports Template as name parameter.
045 *
046 * @throws Error if something went wrong like a thrown exception while rendering the template
047 */
048 public function render($name, array $parameters = [])
049 {
050 return $this->load($name)->render($parameters);
051 }
052
053 /**
054 * {@inheritdoc}
055 *
056 * It also supports Template as name parameter.
057 *
058 * @throws Error if something went wrong like a thrown exception while rendering the template
059 */
060 public function stream($name, array $parameters = [])
061 {
062 $this->load($name)->display($parameters);
063 }
064
065 /**
066 * {@inheritdoc}
067 *
068 * It also supports Template as name parameter.
069 */
070 public function exists($name)
071 {
072 if ($name instanceof Template) {
073 return true;
074 }
075
076 $loader = $this->environment->getLoader();
077
078 if (1 === Environment::MAJOR_VERSION && !$loader instanceof ExistsLoaderInterface) {
079 try {
080 // cast possible TemplateReferenceInterface to string because the
081 // EngineInterface supports them but LoaderInterface does not
082 if ($loader instanceof SourceContextLoaderInterface) {
083 $loader->getSourceContext((string) $name);
084 } else {
085 $loader->getSource((string) $name);
086 }
087
088 return true;
089 } catch (LoaderError $e) {
090 }
091
092 return false;
093 }
094
095 return $loader->exists((string) $name);
096 }
097
098 /**
099 * {@inheritdoc}
100 *
101 * It also supports Template as name parameter.
102 */
103 public function supports($name)
104 {
105 if ($name instanceof Template) {
106 return true;
107 }
108
109 $template = $this->parser->parse($name);
110
111 return 'twig' === $template->get('engine');
112 }
113
114 /**
115 * Loads the given template.
116 *
117 * @param string|TemplateReferenceInterface|Template $name A template name or an instance of
118 * TemplateReferenceInterface or Template
119 *
120 * @return Template
121 *
122 * @throws \InvalidArgumentException if the template does not exist
123 */
124 protected function load($name)
125 {
126 if ($name instanceof Template) {
127 return $name;
128 }
129
130 try {
131 return $this->environment->loadTemplate((string) $name);
132 } catch (LoaderError $e) {
133 throw new \InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
134 }
135 }
136 }
137