Files
picea/src/Extension/TitleExtension.php
T

44 lines
1.0 KiB
PHP

<?php
namespace Picea\Extension;
class TitleExtension implements Extension, FunctionExtension {
public string $token = "title";
public string $title = "";
public function exportFunctions(): array
{
return [
"title" => [$this, 'handleTitle'],
];
}
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string
{
return <<<PHP
<?php
if ( null !== \$title = title($arguments) ) {
echo \$title;
}
?>
PHP;
}
public function handleTitle(? string $set = null, ...$arguments) : ? string
{
if ( $set === null ) {
return $this->title;
}
else {
# Fixed a bug where template inheritance was rewriting title
if ( empty($this->title) ) {
$this->title = $arguments ? sprintf($set, ...$arguments) : $set;
}
}
return null;
}
}