Skip to content

Commit 1f1392d

Browse files
committed
[HttpKernel] simplified and enhanced code managing the hinclude strategy
1 parent 403bb06 commit 1f1392d

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

src/Symfony/Component/HttpKernel/RenderingStrategy/HIncludeRenderingStrategy.php

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class HIncludeRenderingStrategy extends GeneratorAwareRenderingStrategy
3232
*
3333
* @param EngineInterface|\Twig_Environment $templating An EngineInterface or a \Twig_Environment instance
3434
* @param UriSigner $signer A UriSigner instance
35-
* @param string $globalDefaultTemplate The content of the global default template
35+
* @param string $globalDefaultTemplate The global default content (it can be a template name or the content)
3636
*/
3737
public function __construct($templating, UriSigner $signer = null, $globalDefaultTemplate = null)
3838
{
@@ -47,6 +47,10 @@ public function __construct($templating, UriSigner $signer = null, $globalDefaul
4747

4848
/**
4949
* {@inheritdoc}
50+
*
51+
* Additional available options:
52+
*
53+
* * default: The default content (it can be a template name or the content)
5054
*/
5155
public function render($uri, Request $request = null, array $options = array())
5256
{
@@ -58,31 +62,14 @@ public function render($uri, Request $request = null, array $options = array())
5862
$uri = $this->signer->sign($this->generateProxyUri($uri, $request));
5963
}
6064

61-
$defaultTemplate = isset($options['default']) ? $options['default'] : null;
62-
$defaultContent = null;
63-
64-
if (null !== $defaultTemplate) {
65-
if ($this->templateExists($defaultTemplate)) {
66-
$defaultContent = $this->templating->render($defaultContent);
67-
} else {
68-
$defaultContent = $defaultTemplate;
69-
}
70-
} elseif ($this->globalDefaultTemplate) {
71-
$defaultContent = $this->templating->render($this->globalDefaultTemplate);
65+
$template = isset($options['default']) ? $options['default'] : $this->globalDefaultTemplate;
66+
if ($this->templateExists($template)) {
67+
$content = $this->templating->render($template);
68+
} else {
69+
$content = $template;
7270
}
7371

74-
return $this->renderHIncludeTag($uri, $defaultContent);
75-
}
76-
77-
/**
78-
* Renders an HInclude tag.
79-
*
80-
* @param string $uri A URI
81-
* @param string $defaultContent Default content
82-
*/
83-
protected function renderHIncludeTag($uri, $defaultContent = null)
84-
{
85-
return sprintf('<hx:include src="%s">%s</hx:include>', $uri, $defaultContent);
72+
return sprintf('<hx:include src="%s">%s</hx:include>', $uri, $content);
8673
}
8774

8875
private function templateExists($template)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy