nur-sery/nur_src/data/template/StringTemplate.php

35 lines
765 B
PHP
Raw Permalink Normal View History

2023-12-18 05:52:35 +04:00
<?php
namespace nur\data\template;
use nur\data\expr\SimpleContext;
class StringTemplate extends SimpleContext implements ITemplate {
use TTemplate;
/** @return string le texte du modèle */
protected function TEXT(): string {
$text = $this->text;
if ($text === null) $text = static::TEXT;
return $text;
} const TEXT = "";
function __construct(?array $data=null) {
parent::__construct($data);
$this->context = $this;
}
/** @var string */
protected $text;
function setText(string $text): void {
$this->text = $text;
}
/** retourner le texte avec les variables renseignées */
function apply() {
$text = $this->TEXT();
$context = $this->getContext();
return $this->applyRules($text, $context);
}
}