function AbstractSurrogateFragmentRenderer::render
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
- absolute_uri: whether to generate an absolute URI or not. Default is false
Note, that not all surrogate strategies support all options. For now 'alt' and 'comment' are only supported by ESI.
Overrides FragmentRendererInterface::render
See also
Symfony\Component\HttpKernel\HttpCache\SurrogateInterface
File
-
vendor/
symfony/ http-kernel/ Fragment/ AbstractSurrogateFragmentRenderer.php, line 55
Class
- AbstractSurrogateFragmentRenderer
- Implements Surrogate rendering strategy.
Namespace
Symfony\Component\HttpKernel\FragmentCode
public function render(string|ControllerReference $uri, Request $request, array $options = []) : Response {
if (!$this->surrogate || !$this->surrogate
->hasSurrogateCapability($request)) {
$request->attributes
->set('_check_controller_is_allowed', true);
if ($uri instanceof ControllerReference && $this->containsNonScalars($uri->attributes)) {
throw new \InvalidArgumentException('Passing non-scalar values as part of URI attributes to the ESI and SSI rendering strategies is not supported. Use a different rendering strategy or pass scalar values.');
}
return $this->inlineStrategy
->render($uri, $request, $options);
}
$absolute = $options['absolute_uri'] ?? false;
if ($uri instanceof ControllerReference) {
$uri = $this->generateSignedFragmentUri($uri, $request, $absolute);
}
$alt = $options['alt'] ?? null;
if ($alt instanceof ControllerReference) {
$alt = $this->generateSignedFragmentUri($alt, $request, $absolute);
}
$tag = $this->surrogate
->renderIncludeTag($uri, $alt, $options['ignore_errors'] ?? false, $options['comment'] ?? '');
return new Response($tag);
}