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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

FormExtension.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 6.63 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\Extension;
013   
014  use Symfony\Bridge\Twig\Form\TwigRendererInterface;
015  use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
016  use Symfony\Component\DependencyInjection\ContainerInterface;
017  use Symfony\Component\Form\ChoiceList\View\ChoiceView;
018  use Symfony\Component\Form\FormView;
019  use Twig\Environment;
020  use Twig\Extension\AbstractExtension;
021  use Twig\TwigFilter;
022  use Twig\TwigFunction;
023  use Twig\TwigTest;
024   
025  /**
026   * FormExtension extends Twig with form capabilities.
027   *
028   * @author Fabien Potencier <fabien@symfony.com>
029   * @author Bernhard Schussek <bschussek@gmail.com>
030   */
031  class FormExtension extends AbstractExtension implements InitRuntimeInterface
032  {
033      /**
034       * @deprecated since version 3.2, to be removed in 4.0 alongside with magic methods below
035       */
036      private $renderer;
037   
038      public function __construct($renderer = null)
039      {
040          if ($renderer instanceof TwigRendererInterface) {
041              @trigger_error(sprintf('Passing a Twig Form Renderer to the "%s" constructor is deprecated since Symfony 3.2 and won\'t be possible in 4.0. Pass the Twig\Environment to the TwigRendererEngine constructor instead.', static::class), \E_USER_DEPRECATED);
042          } elseif (null !== $renderer && !(\is_array($renderer) && isset($renderer[0], $renderer[1]) && $renderer[0] instanceof ContainerInterface)) {
043              throw new \InvalidArgumentException(sprintf('Passing any arguments to the constructor of "%s" is reserved for internal use.', __CLASS__));
044          }
045          $this->renderer = $renderer;
046      }
047   
048      /**
049       * {@inheritdoc}
050       *
051       * To be removed in 4.0
052       */
053      public function initRuntime(Environment $environment)
054      {
055          if ($this->renderer instanceof TwigRendererInterface) {
056              $this->renderer->setEnvironment($environment);
057          } elseif (\is_array($this->renderer)) {
058              $this->renderer[2] = $environment;
059          }
060      }
061   
062      /**
063       * {@inheritdoc}
064       */
065      public function getTokenParsers()
066      {
067          return [
068              // {% form_theme form "SomeBundle::widgets.twig" %}
069              new FormThemeTokenParser(),
070          ];
071      }
072   
073      /**
074       * {@inheritdoc}
075       */
076      public function getFunctions()
077      {
078          return [
079              new TwigFunction('form_widget', null, ['node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => ['html']]),
080              new TwigFunction('form_errors', null, ['node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => ['html']]),
081              new TwigFunction('form_label', null, ['node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => ['html']]),
082              new TwigFunction('form_row', null, ['node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => ['html']]),
083              new TwigFunction('form_rest', null, ['node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => ['html']]),
084              new TwigFunction('form', null, ['node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => ['html']]),
085              new TwigFunction('form_start', null, ['node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => ['html']]),
086              new TwigFunction('form_end', null, ['node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => ['html']]),
087              new TwigFunction('csrf_token', ['Symfony\Component\Form\FormRenderer', 'renderCsrfToken']),
088          ];
089      }
090   
091      /**
092       * {@inheritdoc}
093       */
094      public function getFilters()
095      {
096          return [
097              new TwigFilter('humanize', ['Symfony\Component\Form\FormRenderer', 'humanize']),
098              new TwigFilter('form_encode_currency', ['Symfony\Component\Form\FormRenderer', 'encodeCurrency'], ['is_safe' => ['html'], 'needs_environment' => true]),
099          ];
100      }
101   
102      /**
103       * {@inheritdoc}
104       */
105      public function getTests()
106      {
107          return [
108              new TwigTest('selectedchoice', 'Symfony\Bridge\Twig\Extension\twig_is_selected_choice'),
109              new TwigTest('rootform', 'Symfony\Bridge\Twig\Extension\twig_is_root_form'),
110          ];
111      }
112   
113      /**
114       * @internal
115       */
116      public function __get($name)
117      {
118          if ('renderer' === $name) {
119              @trigger_error(sprintf('Using the "%s::$renderer" property is deprecated since Symfony 3.2 as it will be removed in 4.0.', __CLASS__), \E_USER_DEPRECATED);
120   
121              if (\is_array($this->renderer)) {
122                  $renderer = $this->renderer[0]->get($this->renderer[1]);
123                  if (isset($this->renderer[2]) && $renderer instanceof TwigRendererInterface) {
124                      $renderer->setEnvironment($this->renderer[2]);
125                  }
126                  $this->renderer = $renderer;
127              }
128          }
129   
130          return $this->$name;
131      }
132   
133      /**
134       * @internal
135       */
136      public function __set($name, $value)
137      {
138          if ('renderer' === $name) {
139              @trigger_error(sprintf('Using the "%s::$renderer" property is deprecated since Symfony 3.2 as it will be removed in 4.0.', __CLASS__), \E_USER_DEPRECATED);
140          }
141   
142          $this->$name = $value;
143      }
144   
145      /**
146       * @internal
147       */
148      public function __isset($name)
149      {
150          if ('renderer' === $name) {
151              @trigger_error(sprintf('Using the "%s::$renderer" property is deprecated since Symfony 3.2 as it will be removed in 4.0.', __CLASS__), \E_USER_DEPRECATED);
152          }
153   
154          return isset($this->$name);
155      }
156   
157      /**
158       * @internal
159       */
160      public function __unset($name)
161      {
162          if ('renderer' === $name) {
163              @trigger_error(sprintf('Using the "%s::$renderer" property is deprecated since Symfony 3.2 as it will be removed in 4.0.', __CLASS__), \E_USER_DEPRECATED);
164          }
165   
166          unset($this->$name);
167      }
168   
169      /**
170       * {@inheritdoc}
171       */
172      public function getName()
173      {
174          return 'form';
175      }
176  }
177   
178  /**
179   * Returns whether a choice is selected for a given form value.
180   *
181   * This is a function and not callable due to performance reasons.
182   *
183   * @param string|array $selectedValue The selected value to compare
184   *
185   * @return bool Whether the choice is selected
186   *
187   * @see ChoiceView::isSelected()
188   */
189  function twig_is_selected_choice(ChoiceView $choice, $selectedValue)
190  {
191      if (\is_array($selectedValue)) {
192          return \in_array($choice->value, $selectedValue, true);
193      }
194   
195      return $choice->value === $selectedValue;
196  }
197   
198  /**
199   * @internal
200   */
201  function twig_is_root_form(FormView $formView)
202  {
203      return null === $formView->parent;
204  }
205