Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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

EsiFragmentRenderer.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 3.14 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\Esi;
018  use Symfony\Component\HttpKernel\UriSigner;
019   
020  /**
021   * Implements the ESI rendering strategy.
022   *
023   * @author Fabien Potencier <fabien@symfony.com>
024   */
025  class EsiFragmentRenderer extends RoutableFragmentRenderer
026  {
027      private $esi;
028      private $inlineStrategy;
029      private $signer;
030   
031      /**
032       * Constructor.
033       *
034       * The "fallback" strategy when ESI is not available should always be an
035       * instance of InlineFragmentRenderer.
036       *
037       * @param Esi                       $esi            An Esi instance
038       * @param FragmentRendererInterface $inlineStrategy The inline strategy to use when ESI is not supported
039       * @param UriSigner                 $signer
040       */
041      public function __construct(Esi $esi, FragmentRendererInterface $inlineStrategy, UriSigner $signer = null)
042      {
043          $this->esi = $esi;
044          $this->inlineStrategy = $inlineStrategy;
045          $this->signer = $signer;
046      }
047   
048      /**
049       * {@inheritdoc}
050       *
051       * Note that if the current Request has no ESI capability, this method
052       * falls back to use the inline rendering strategy.
053       *
054       * Additional available options:
055       *
056       *  * alt: an alternative URI to render in case of an error
057       *  * comment: a comment to add when returning an esi:include tag
058       *
059       * @see Symfony\Component\HttpKernel\HttpCache\ESI
060       */
061      public function render($uri, Request $request, array $options = array())
062      {
063          if (!$this->esi->hasSurrogateEsiCapability($request)) {
064              return $this->inlineStrategy->render($uri, $request, $options);
065          }
066   
067          if ($uri instanceof ControllerReference) {
068              $uri = $this->generateSignedFragmentUri($uri, $request);
069          }
070   
071          $alt = isset($options['alt']) ? $options['alt'] : null;
072          if ($alt instanceof ControllerReference) {
073              $alt = $this->generateSignedFragmentUri($alt, $request);
074          }
075   
076          $tag = $this->esi->renderIncludeTag($uri, $alt, isset($options['ignore_errors']) ? $options['ignore_errors'] : false, isset($options['comment']) ? $options['comment'] : '');
077   
078          return new Response($tag);
079      }
080   
081      /**
082       * {@inheritdoc}
083       */
084      public function getName()
085      {
086          return 'esi';
087      }
088   
089      private function generateSignedFragmentUri($uri, Request $request)
090      {
091          if (null === $this->signer) {
092              throw new \LogicException('You must use a URI when using the ESI rendering strategy or set a URL signer.');
093          }
094   
095          // we need to sign the absolute URI, but want to return the path only.
096          $fragmentUri = $this->signer->sign($this->generateFragmentUri($uri, $request, true));
097   
098          return substr($fragmentUri, strlen($request->getSchemeAndHttpHost()));
099      }
100  }
101