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

AbstractSurrogateFragmentRenderer.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 4.01 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\Component\HttpKernel\Fragment;
013   
014  use Symfony\Component\HttpFoundation\Request;
015  use Symfony\Component\HttpFoundation\Response;
016  use Symfony\Component\HttpKernel\Controller\ControllerReference;
017  use Symfony\Component\HttpKernel\HttpCache\SurrogateInterface;
018  use Symfony\Component\HttpKernel\UriSigner;
019   
020  /**
021   * Implements Surrogate rendering strategy.
022   *
023   * @author Fabien Potencier <fabien@symfony.com>
024   */
025  abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRenderer
026  {
027      private $surrogate;
028      private $inlineStrategy;
029      private $signer;
030   
031      /**
032       * The "fallback" strategy when surrogate is not available should always be an
033       * instance of InlineFragmentRenderer.
034       *
035       * @param SurrogateInterface        $surrogate      An Surrogate instance
036       * @param FragmentRendererInterface $inlineStrategy The inline strategy to use when the surrogate is not supported
037       * @param UriSigner                 $signer
038       */
039      public function __construct(SurrogateInterface $surrogate = null, FragmentRendererInterface $inlineStrategy, UriSigner $signer = null)
040      {
041          $this->surrogate = $surrogate;
042          $this->inlineStrategy = $inlineStrategy;
043          $this->signer = $signer;
044      }
045   
046      /**
047       * {@inheritdoc}
048       *
049       * Note that if the current Request has no surrogate capability, this method
050       * falls back to use the inline rendering strategy.
051       *
052       * Additional available options:
053       *
054       *  * alt: an alternative URI to render in case of an error
055       *  * comment: a comment to add when returning the surrogate tag
056       *
057       * Note, that not all surrogate strategies support all options. For now
058       * 'alt' and 'comment' are only supported by ESI.
059       *
060       * @see Symfony\Component\HttpKernel\HttpCache\SurrogateInterface
061       */
062      public function render($uri, Request $request, array $options = [])
063      {
064          if (!$this->surrogate || !$this->surrogate->hasSurrogateCapability($request)) {
065              if ($uri instanceof ControllerReference && $this->containsNonScalars($uri->attributes)) {
066                  @trigger_error('Passing non-scalar values as part of URI attributes to the ESI and SSI rendering strategies is deprecated since Symfony 3.1, and will be removed in 4.0. Use a different rendering strategy or pass scalar values.', \E_USER_DEPRECATED);
067              }
068   
069              return $this->inlineStrategy->render($uri, $request, $options);
070          }
071   
072          if ($uri instanceof ControllerReference) {
073              $uri = $this->generateSignedFragmentUri($uri, $request);
074          }
075   
076          $alt = isset($options['alt']) ? $options['alt'] : null;
077          if ($alt instanceof ControllerReference) {
078              $alt = $this->generateSignedFragmentUri($alt, $request);
079          }
080   
081          $tag = $this->surrogate->renderIncludeTag($uri, $alt, isset($options['ignore_errors']) ? $options['ignore_errors'] : false, isset($options['comment']) ? $options['comment'] : '');
082   
083          return new Response($tag);
084      }
085   
086      private function generateSignedFragmentUri($uri, Request $request)
087      {
088          if (null === $this->signer) {
089              throw new \LogicException('You must use a URI when using the ESI rendering strategy or set a URL signer.');
090          }
091   
092          // we need to sign the absolute URI, but want to return the path only.
093          $fragmentUri = $this->signer->sign($this->generateFragmentUri($uri, $request, true));
094   
095          return substr($fragmentUri, \strlen($request->getSchemeAndHttpHost()));
096      }
097   
098      private function containsNonScalars(array $values)
099      {
100          foreach ($values as $value) {
101              if (\is_array($value)) {
102                  return $this->containsNonScalars($value);
103              } elseif (!is_scalar($value) && null !== $value) {
104                  return true;
105              }
106          }
107   
108          return false;
109      }
110  }
111