mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Fix: intersect the names of temporary variables during force include
This commit is contained in:
parent
56b7fe8bb0
commit
82631f54c1
@ -34,8 +34,4 @@
|
|||||||
<directory>./src/</directory>
|
<directory>./src/</directory>
|
||||||
</whitelist>
|
</whitelist>
|
||||||
</filter>
|
</filter>
|
||||||
|
|
||||||
<logging>
|
|
||||||
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
|
||||||
</logging>
|
|
||||||
</phpunit>
|
</phpunit>
|
@ -39,7 +39,8 @@ class Compiler
|
|||||||
if ($name && ($tpl->getStorage()->getOptions() & \Fenom::FORCE_INCLUDE)) {
|
if ($name && ($tpl->getStorage()->getOptions() & \Fenom::FORCE_INCLUDE)) {
|
||||||
$inc = $tpl->getStorage()->compile($name, false);
|
$inc = $tpl->getStorage()->compile($name, false);
|
||||||
$tpl->addDepend($inc);
|
$tpl->addDepend($inc);
|
||||||
return '$_tpl = (array)$tpl; $tpl->exchangeArray(' . self::toArray($p) . '+$_tpl); ?>' . $inc->getBody() . '<?php $tpl->exchangeArray($_tpl); unset($_tpl);';
|
$var = $tpl->tmpVar();
|
||||||
|
return $var.' = (array)$tpl; $tpl->exchangeArray(' . self::toArray($p) . '+'.$var.'); ?>' . $inc->getBody() . '<?php $tpl->exchangeArray('.$var.'); unset('.$var.');';
|
||||||
} else {
|
} else {
|
||||||
return '$tpl->getStorage()->getTemplate(' . $cname . ')->display(' . self::toArray($p) . '+(array)$tpl);';
|
return '$tpl->getStorage()->getTemplate(' . $cname . ')->display(' . self::toArray($p) . '+(array)$tpl);';
|
||||||
}
|
}
|
||||||
@ -47,7 +48,8 @@ class Compiler
|
|||||||
if ($name && ($tpl->getStorage()->getOptions() & \Fenom::FORCE_INCLUDE)) {
|
if ($name && ($tpl->getStorage()->getOptions() & \Fenom::FORCE_INCLUDE)) {
|
||||||
$inc = $tpl->getStorage()->compile($name, false);
|
$inc = $tpl->getStorage()->compile($name, false);
|
||||||
$tpl->addDepend($inc);
|
$tpl->addDepend($inc);
|
||||||
return '$_tpl = (array)$tpl; ?>' . $inc->getBody() . '<?php $tpl->exchangeArray($_tpl); unset($_tpl);';
|
$var = $tpl->tmpVar();
|
||||||
|
return $var.' = (array)$tpl; ?>' . $inc->getBody() . '<?php $tpl->exchangeArray('.$var.'); unset('.$var.');';
|
||||||
} else {
|
} else {
|
||||||
return '$tpl->getStorage()->getTemplate(' . $cname . ')->display((array)$tpl);';
|
return '$tpl->getStorage()->getTemplate(' . $cname . ')->display((array)$tpl);';
|
||||||
}
|
}
|
||||||
|
@ -99,6 +99,11 @@ class Template extends Render
|
|||||||
|
|
||||||
private $_filters = array();
|
private $_filters = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int crc32 of the template name
|
||||||
|
*/
|
||||||
|
private $_crc = 0;
|
||||||
|
|
||||||
protected static $_tests = array(
|
protected static $_tests = array(
|
||||||
'integer' => 'is_int(%s)',
|
'integer' => 'is_int(%s)',
|
||||||
'int' => 'is_int(%s)',
|
'int' => 'is_int(%s)',
|
||||||
@ -157,6 +162,7 @@ class Template extends Render
|
|||||||
public function load($name, $compile = true)
|
public function load($name, $compile = true)
|
||||||
{
|
{
|
||||||
$this->_name = $name;
|
$this->_name = $name;
|
||||||
|
$this->_crc = crc32($this->_name);
|
||||||
if ($provider = strstr($name, ":", true)) {
|
if ($provider = strstr($name, ":", true)) {
|
||||||
$this->_scm = $provider;
|
$this->_scm = $provider;
|
||||||
$this->_base_name = substr($name, strlen($provider) + 1);
|
$this->_base_name = substr($name, strlen($provider) + 1);
|
||||||
@ -300,7 +306,7 @@ class Template extends Render
|
|||||||
*/
|
*/
|
||||||
public function tmpVar()
|
public function tmpVar()
|
||||||
{
|
{
|
||||||
return '$t' . ($this->i++);
|
return sprintf('$t%u_%d', $this->_crc, $this->i++);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user