35 lines
		
	
	
		
			765 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			765 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?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);
 | |
|   }
 | |
| }
 |