33 lines
836 B
PHP
33 lines
836 B
PHP
<?php
|
|
namespace Hanyuu\Templating;
|
|
|
|
class TemplateVars {
|
|
public function __construct(
|
|
private ?TemplateVars $parent = null,
|
|
private array $vars = []
|
|
) {}
|
|
|
|
public function getVars(): array {
|
|
$vars = $this->vars;
|
|
if($this->parent !== null)
|
|
$vars += $this->parent->getVars();
|
|
return $vars;
|
|
}
|
|
|
|
public function getVar(string $name, mixed $default = null): mixed {
|
|
if(isset($this->vars[$name]))
|
|
return $this->vars[$name];
|
|
if($this->parent !== null)
|
|
return $this->parent->getVar($name, $default);
|
|
return $default;
|
|
}
|
|
|
|
public function setVar(string $name, mixed $value): void {
|
|
$this->vars[$name] = $value;
|
|
}
|
|
|
|
public function removeVar(string $name): void {
|
|
unset($this->vars[$name]);
|
|
}
|
|
}
|