class HIncludeFragmentRenderer
Implements the Hinclude rendering strategy.
@author Fabien Potencier <fabien@symfony.com>
Hierarchy
- class \Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer implements \Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface
- class \Symfony\Component\HttpKernel\Fragment\HIncludeFragmentRenderer extends \Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer
Expanded class hierarchy of HIncludeFragmentRenderer
File
-
vendor/
symfony/ http-kernel/ Fragment/ HIncludeFragmentRenderer.php, line 25
Namespace
Symfony\Component\HttpKernel\FragmentView source
class HIncludeFragmentRenderer extends RoutableFragmentRenderer {
/**
* @param string|null $globalDefaultTemplate The global default content (it can be a template name or the content)
*/
public function __construct(?Environment $twig = null, ?UriSigner $signer = null, ?string $globalDefaultTemplate = null, string $charset = 'utf-8') {
}
/**
* Checks if a templating engine has been set.
*/
public function hasTemplating() : bool {
return null !== $this->twig;
}
/**
* Additional available options:
*
* * default: The default content (it can be a template name or the content)
* * id: An optional hx:include tag id attribute
* * attributes: An optional array of hx:include tag attributes
*/
public function render(string|ControllerReference $uri, Request $request, array $options = []) : Response {
if ($uri instanceof ControllerReference) {
$uri = (new FragmentUriGenerator($this->fragmentPath, $this->signer))
->generate($uri, $request);
}
// We need to replace ampersands in the URI with the encoded form in order to return valid html/xml content.
$uri = str_replace('&', '&', $uri);
$template = $options['default'] ?? $this->globalDefaultTemplate;
if (null !== $this->twig && $template && $this->twig
->getLoader()
->exists($template)) {
$content = $this->twig
->render($template);
}
else {
$content = $template;
}
$attributes = isset($options['attributes']) && \is_array($options['attributes']) ? $options['attributes'] : [];
if (isset($options['id']) && $options['id']) {
$attributes['id'] = $options['id'];
}
$renderedAttributes = '';
if (\count($attributes) > 0) {
$flags = \ENT_QUOTES | \ENT_SUBSTITUTE;
foreach ($attributes as $attribute => $value) {
$renderedAttributes .= \sprintf(' %s="%s"', htmlspecialchars($attribute, $flags, $this->charset, false), htmlspecialchars($value, $flags, $this->charset, false));
}
}
return new Response(\sprintf('<hx:include src="%s"%s>%s</hx:include>', $uri, $renderedAttributes, $content));
}
public function getName() : string {
return 'hinclude';
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
HIncludeFragmentRenderer::getName | public | function | Gets the name of the strategy. | Overrides FragmentRendererInterface::getName |
HIncludeFragmentRenderer::hasTemplating | public | function | Checks if a templating engine has been set. | |
HIncludeFragmentRenderer::render | public | function | Additional available options: | Overrides FragmentRendererInterface::render |
HIncludeFragmentRenderer::__construct | public | function | ||
RoutableFragmentRenderer::$fragmentPath | protected | property | @internal | |
RoutableFragmentRenderer::generateFragmentUri | protected | function | Generates a fragment URI for a given controller. | |
RoutableFragmentRenderer::setFragmentPath | public | function | Sets the fragment path that triggers the fragment listener. |