Skip to content

Commit

Permalink
Merge branch 'hotfix/ZF2-86' of https://github.com/jtai/zf2 into hotf…
Browse files Browse the repository at this point in the history
…ix/zf2-86
  • Loading branch information
weierophinney committed Oct 26, 2011
2 parents 9ef861f + 6554cf9 commit 5201a63
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
14 changes: 6 additions & 8 deletions library/Zend/View/PhpRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class PhpRenderer implements Renderer, Pluggable
private $vars;

/**
* @var ArrayAccess|array Temporary variable cache; used when variables passed to render()
* @var array Temporary variable stack; used when variables passed to render()
*/
private $varsCache;
private $varsCache = array();

/**
* Constructor.
Expand Down Expand Up @@ -414,8 +414,9 @@ public function render($name, $vars = null)
$this->file = $this->resolver($name);
unset($name); // remove $name from local scope

$this->varsCache[] = $this->vars();

if (null !== $vars) {
$this->varsCache = $this->vars();
$this->setVars($vars);
}
unset($vars);
Expand All @@ -428,15 +429,12 @@ public function render($name, $vars = null)
}
extract($__vars);
unset($__vars); // remove $__vars from local scope

ob_start();
include $this->file;
$content = ob_get_clean();

if (null !== $this->varsCache) {
$this->setVars($this->varsCache);
$this->varsCache = null;
}
$this->setVars(array_pop($this->varsCache));

return $this->getFilterChain()->filter($content); // filter output
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Zend/View/PhpRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ public function testPassingVariablesObjectToSetVarsShouldUseItDirectoy()
$this->assertSame($vars, $this->renderer->vars());
}

/**
* @group ZF2-86
*/
public function testNestedRenderingRestoresVariablesCorrectly()
{
$expected = "inner\n<p>content</p>";
$this->renderer->resolver()->addPath(__DIR__ . '/_templates');
$test = $this->renderer->render('testNestedOuter.phtml', array('content' => '<p>content</p>'));
$this->assertEquals($expected, $test);
}

/**
* @group convenience-api
*/
Expand Down
1 change: 1 addition & 0 deletions tests/Zend/View/_templates/testNestedInner.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inner
4 changes: 4 additions & 0 deletions tests/Zend/View/_templates/testNestedOuter.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
?>
<?php echo $this->render('testNestedInner.phtml') ?>
<?php echo $this->raw('content') ?>

0 comments on commit 5201a63

Please sign in to comment.