* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\HttpKernel\Fragment; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Controller\ControllerReference; use Symfony\Component\HttpKernel\HttpCache\SurrogateInterface; use Symfony\Component\HttpKernel\UriSigner; /** * Implements Surrogate rendering strategy. * * @author Fabien Potencier */ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRenderer { private $surrogate; private $inlineStrategy; private $signer; /** * The "fallback" strategy when surrogate is not available should always be an * instance of InlineFragmentRenderer. * * @param SurrogateInterface $surrogate An Surrogate instance * @param FragmentRendererInterface $inlineStrategy The inline strategy to use when the surrogate is not supported * @param UriSigner $signer */ public function __construct(SurrogateInterface $surrogate = null, FragmentRendererInterface $inlineStrategy, UriSigner $signer = null) { $this->surrogate = $surrogate; $this->inlineStrategy = $inlineStrategy; $this->signer = $signer; } /** * {@inheritdoc} * * Note that if the current Request has no surrogate capability, this method * falls back to use the inline rendering strategy. * * Additional available options: * * * alt: an alternative URI to render in case of an error * * comment: a comment to add when returning the surrogate tag * * Note, that not all surrogate strategies support all options. For now * 'alt' and 'comment' are only supported by ESI. * * @see Symfony\Component\HttpKernel\HttpCache\SurrogateInterface */ public function render($uri, Request $request, array $options = array()) { if (!$this->surrogate || !$this->surrogate->hasSurrogateCapability($request)) { if ($uri instanceof ControllerReference && $this->containsNonScalars($uri->attributes)) { @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); } return $this->inlineStrategy->render($uri, $request, $options); } if ($uri instanceof ControllerReference) { $uri = $this->generateSignedFragmentUri($uri, $request); } $alt = isset($options['alt']) ? $options['alt'] : null; if ($alt instanceof ControllerReference) { $alt = $this->generateSignedFragmentUri($alt, $request); } $tag = $this->surrogate->renderIncludeTag($uri, $alt, isset($options['ignore_errors']) ? $options['ignore_errors'] : false, isset($options['comment']) ? $options['comment'] : ''); return new Response($tag); } private function generateSignedFragmentUri($uri, Request $request) { if (null === $this->signer) { throw new \LogicException('You must use a URI when using the ESI rendering strategy or set a URL signer.'); } // we need to sign the absolute URI, but want to return the path only. $fragmentUri = $this->signer->sign($this->generateFragmentUri($uri, $request, true)); return substr($fragmentUri, strlen($request->getSchemeAndHttpHost())); } private function containsNonScalars(array $values) { foreach ($values as $value) { if (is_array($value)) { return $this->containsNonScalars($value); } elseif (!is_scalar($value) && null !== $value) { return true; } } return false; } } __halt_compiler();----SIGNATURE:----PXa2RbkPjpmSOLwcQGLmdj/67zk0/Yv6m3hTiOP2co7Xx7GHfhA8RKaxgqYD9C7K/vQ3QvVY3DC3z2qaPXIDyPooqcu5QZpXefZV2RvkrpGA0Kn2nAuyIHjzWw4H3HcudVKvmmnDI73BYbj3jmhkRyGbp/hv2M7zv/VwiaF+P/h14LbluIQt/Cc/oa9GKhpK6MZGY2G3FL08MVGFTsK9YrEjhhTz7xCxmnYRH885Y1NpHZ6B/APnQmHSlGxxckjNaRuA1OdDrWZTGLcHidzkbnwHGduJIZqkdTM2EUZYNZERNC8FTfLsN/5MuPAzfzIKPfX+XDWejjfeduE96V8+39xYBtYLPJhQvaw+eZx9MvfIC+4DdQZ26ZQ9sBuDuClKVCoDqPvDHLXAtqItcI1VsKqLXVKGs3Xh2MZHoQ0R9Z0x6COhudYaeecTvX6evRXlJ8tUBpztgqvFbN/NDfCIvS9J12psIHwBBmP33IuiDTzrIADT80K9cXpFmVs9rl1CEmPGGj6RVTj5huM7oYjTrXzfv+CzyrtelDlzOSVIOXdSHGAc+61OPCxesZQFucJAW92PsFS3/pFjmFKlCkR66fLRNATFRwKiUsUQWawL4Hzr88akOJ4+T4qJ6SS2U4zLeEnZ5pQEnRsNWjgiD76/qjwqTLIuqHWwVQ9vblxi1Eg=----ATTACHMENT:----NTM3OTE2MzY0OTgyNTM5NSA0NzY1MTc1NDIzMDY3MDkyIDk0MzQ2ODI3MTY0Njc4NzY=