mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-06 10:11:38 +09:00
Inherit parent vars and add own vars when a template is included with vars from another template that has vars; add unit tests for vars inheritance
This commit is contained in:
parent
5b47151440
commit
6085b82d19
7 changed files with 92 additions and 12 deletions
|
|
@ -215,7 +215,7 @@ class Template
|
|||
}
|
||||
elseif (is_object($vars))
|
||||
{
|
||||
$this->vars = $vars;
|
||||
$this->vars = clone $vars;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -223,6 +223,25 @@ class Template
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add vars.
|
||||
*
|
||||
* @param array|object $vars
|
||||
* @return void
|
||||
*/
|
||||
public function addVars($vars): void
|
||||
{
|
||||
if (!isset($this->vars))
|
||||
{
|
||||
$this->vars = new \stdClass;
|
||||
}
|
||||
|
||||
foreach (is_object($vars) ? get_object_vars($vars) : $vars as $key => $val)
|
||||
{
|
||||
$this->vars->$key = $val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile and execute a template file.
|
||||
*
|
||||
|
|
@ -535,9 +554,13 @@ class Template
|
|||
}
|
||||
|
||||
// Set variables.
|
||||
if ($this->vars)
|
||||
{
|
||||
$template->setVars($this->vars);
|
||||
}
|
||||
if ($vars !== null)
|
||||
{
|
||||
$template->setVars($vars);
|
||||
$template->addVars($vars);
|
||||
}
|
||||
|
||||
// Compile and return.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue