[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
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\Esi; 18 use Symfony\Component\HttpKernel\UriSigner; 19 20 /** 21 * Implements the ESI rendering strategy. 22 * 23 * @author Fabien Potencier <fabien@symfony.com> 24 */ 25 class EsiFragmentRenderer extends RoutableFragmentRenderer 26 { 27 private $esi; 28 private $inlineStrategy; 29 private $signer; 30 31 /** 32 * Constructor. 33 * 34 * The "fallback" strategy when ESI is not available should always be an 35 * instance of InlineFragmentRenderer. 36 * 37 * @param Esi $esi An Esi instance 38 * @param FragmentRendererInterface $inlineStrategy The inline strategy to use when ESI is not supported 39 * @param UriSigner $signer 40 */ 41 public function __construct(Esi $esi, FragmentRendererInterface $inlineStrategy, UriSigner $signer = null) 42 { 43 $this->esi = $esi; 44 $this->inlineStrategy = $inlineStrategy; 45 $this->signer = $signer; 46 } 47 48 /** 49 * {@inheritdoc} 50 * 51 * Note that if the current Request has no ESI capability, this method 52 * falls back to use the inline rendering strategy. 53 * 54 * Additional available options: 55 * 56 * * alt: an alternative URI to render in case of an error 57 * * comment: a comment to add when returning an esi:include tag 58 * 59 * @see Esi 60 */ 61 public function render($uri, Request $request, array $options = array()) 62 { 63 if (!$this->esi->hasSurrogateEsiCapability($request)) { 64 return $this->inlineStrategy->render($uri, $request, $options); 65 } 66 67 if ($uri instanceof ControllerReference) { 68 $uri = $this->generateSignedFragmentUri($uri, $request); 69 } 70 71 $alt = isset($options['alt']) ? $options['alt'] : null; 72 if ($alt instanceof ControllerReference) { 73 $alt = $this->generateSignedFragmentUri($alt, $request); 74 } 75 76 $tag = $this->esi->renderIncludeTag($uri, $alt, isset($options['ignore_errors']) ? $options['ignore_errors'] : false, isset($options['comment']) ? $options['comment'] : ''); 77 78 return new Response($tag); 79 } 80 81 /** 82 * {@inheritdoc} 83 */ 84 public function getName() 85 { 86 return 'esi'; 87 } 88 89 private function generateSignedFragmentUri($uri, Request $request) 90 { 91 if (null === $this->signer) { 92 throw new \LogicException('You must use a URI when using the ESI rendering strategy or set a URL signer.'); 93 } 94 95 // we need to sign the absolute URI, but want to return the path only. 96 $fragmentUri = $this->signer->sign($this->generateFragmentUri($uri, $request, true)); 97 98 return substr($fragmentUri, strlen($request->getSchemeAndHttpHost())); 99 } 100 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |