Skip to content

Commit

Permalink
[Form][TwigBridge] Make the template cache more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Jun 12, 2011
1 parent 8677aa3 commit 9135f96
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Symfony/Bridge/Twig/Extension/FormExtension.php
Expand Up @@ -56,7 +56,7 @@ public function initRuntime(\Twig_Environment $environment)
public function setTheme(FormView $view, array $resources)
{
$this->themes->attach($view, $resources);
$this->templates->detach($view);
$this->templates = new \SplObjectStorage();
}

/**
Expand Down Expand Up @@ -263,15 +263,14 @@ protected function render(FormView $view, $section, array $variables = array())
protected function getTemplates(FormView $view)
{
if (!$this->templates->contains($view)) {
$templates = array();
$parent = $view;
do {
if (isset($this->themes[$parent])) {
$templates = array_merge($this->themes[$parent], $templates);
}
} while ($parent = $parent->getParent());

$templates = array_merge($this->resources, $templates);
$rootView = !$view->hasParent();

$templates = $rootView ? $this->resources : array();

if (isset($this->themes[$view])) {
$templates = array_merge($templates, $this->themes[$view]);
}

foreach ($templates as $i => $template) {
if (!$template instanceof \Twig_Template) {
Expand All @@ -280,6 +279,10 @@ protected function getTemplates(FormView $view)
$templates[$i] = $template;
}

if (!$rootView) {
$templates = array_merge($this->getTemplates($view->getParent()), $templates);
}

$this->templates->attach($view, $templates);
} else {
$templates = $this->templates[$view];
Expand Down

0 comments on commit 9135f96

Please sign in to comment.