[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/vendor/symfony/http-kernel/Fragment/ -> AbstractSurrogateFragmentRenderer.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\HttpKernel\Fragment;
  13  
  14  use Symfony\Component\HttpFoundation\Request;
  15  use Symfony\Component\HttpFoundation\Response;
  16  use Symfony\Component\HttpKernel\Controller\ControllerReference;
  17  use Symfony\Component\HttpKernel\HttpCache\SurrogateInterface;
  18  use Symfony\Component\HttpKernel\UriSigner;
  19  
  20  /**
  21   * Implements Surrogate rendering strategy.
  22   *
  23   * @author Fabien Potencier <fabien@symfony.com>
  24   */
  25  abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRenderer
  26  {
  27      private $surrogate;
  28      private $inlineStrategy;
  29      private $signer;
  30  
  31      /**
  32       * The "fallback" strategy when surrogate is not available should always be an
  33       * instance of InlineFragmentRenderer.
  34       *
  35       * @param SurrogateInterface        $surrogate      An Surrogate instance
  36       * @param FragmentRendererInterface $inlineStrategy The inline strategy to use when the surrogate is not supported
  37       * @param UriSigner                 $signer
  38       */
  39      public function __construct(SurrogateInterface $surrogate = null, FragmentRendererInterface $inlineStrategy, UriSigner $signer = null)
  40      {
  41          $this->surrogate = $surrogate;
  42          $this->inlineStrategy = $inlineStrategy;
  43          $this->signer = $signer;
  44      }
  45  
  46      /**
  47       * {@inheritdoc}
  48       *
  49       * Note that if the current Request has no surrogate capability, this method
  50       * falls back to use the inline rendering strategy.
  51       *
  52       * Additional available options:
  53       *
  54       *  * alt: an alternative URI to render in case of an error
  55       *  * comment: a comment to add when returning the surrogate tag
  56       *
  57       * Note, that not all surrogate strategies support all options. For now
  58       * 'alt' and 'comment' are only supported by ESI.
  59       *
  60       * @see Symfony\Component\HttpKernel\HttpCache\SurrogateInterface
  61       */
  62      public function render($uri, Request $request, array $options = array())
  63      {
  64          if (!$this->surrogate || !$this->surrogate->hasSurrogateCapability($request)) {
  65              return $this->inlineStrategy->render($uri, $request, $options);
  66          }
  67  
  68          if ($uri instanceof ControllerReference) {
  69              $uri = $this->generateSignedFragmentUri($uri, $request);
  70          }
  71  
  72          $alt = isset($options['alt']) ? $options['alt'] : null;
  73          if ($alt instanceof ControllerReference) {
  74              $alt = $this->generateSignedFragmentUri($alt, $request);
  75          }
  76  
  77          $tag = $this->surrogate->renderIncludeTag($uri, $alt, isset($options['ignore_errors']) ? $options['ignore_errors'] : false, isset($options['comment']) ? $options['comment'] : '');
  78  
  79          return new Response($tag);
  80      }
  81  
  82      private function generateSignedFragmentUri($uri, Request $request)
  83      {
  84          if (null === $this->signer) {
  85              throw new \LogicException('You must use a URI when using the ESI rendering strategy or set a URL signer.');
  86          }
  87  
  88          // we need to sign the absolute URI, but want to return the path only.
  89          $fragmentUri = $this->signer->sign($this->generateFragmentUri($uri, $request, true));
  90  
  91          return substr($fragmentUri, \strlen($request->getSchemeAndHttpHost()));
  92      }
  93  }


Generated: Tue Apr 7 19:42:26 2020 Cross-referenced by PHPXref 0.7.1