8000 [WIP] Kernel refactor by fabpot · Pull Request #6459 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WIP] Kernel refactor #6459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jan 11, 2013
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[HttpKernel] simplified and enhanced code managing the hinclude strategy
  • Loading branch information
fabpot committed Jan 10, 2013
commit 1f1392dc8bce232a3111a08e1627884d77c69901
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class HIncludeRenderingStrategy extends GeneratorAwareRenderingStrategy
*
* @param EngineInterface|\Twig_Environment $templating An EngineInterface or a \Twig_Environment instance
* @param UriSigner $signer A UriSigner instance
* @param string $globalDefaultTemplate The content of the global default template
* @param string $globalDefaultTemplate The global default content (it can be a template name or the content)
*/
public function __construct($templating, UriSigner $signer = null, $globalDefaultTemplate = null)
{
Expand All @@ -47,6 +47,10 @@ public function __construct($templating, UriSigner $signer = null, $globalDefaul

/**
* {@inheritdoc}
*
* Additional available options:
*
* * default: The default content (it can be a template name or the content)
*/
public function render($uri, Request $request = null, array $options = array())
{
Expand All @@ -58,31 +62,14 @@ public function render($uri, Request $request = null, array $options = array())
$uri = $this->signer->sign($this->generateProxyUri($uri, $request));
}

$defaultTemplate = isset($options['default']) ? $options['default'] : null;
$defaultContent = null;

if (null !== $defaultTemplate) {
if ($this->templateExists($defaultTemplate)) {
$defaultContent = $this->templating->render($defaultContent);
} else {
$defaultContent = $defaultTemplate;
}
} elseif ($this->globalDefaultTemplate) {
$defaultContent = $this->templating->render($this->globalDefaultTemplate);
$template = isset($options['default']) ? $options['default'] : $this->globalDefaultTemplate;
if ($this->templateExists($template)) {
$content = $this->templating->render($template);
} else {
$content = $template;
}

return $this->renderHIncludeTag($uri, $defaultContent);
}

/**
* Renders an HInclude tag.
*
* @param string $uri A URI
* @param string $defaultContent Default content
*/
protected function renderHIncludeTag($uri, $defaultContent = null)
{
return sprintf('<hx:include src="%s">%s</hx:include>', $uri, $defaultContent);
return sprintf('<hx:include src="%s">%s</hx:include>', $uri, $content);
}

private function templateExists($template)
Expand Down
0