File modules/template_engine/element/PHPBlockElement.class.php
Last commit: Sun Nov 1 00:36:50 2020 +0100 Jan Dankert Refactoring: Only using the configuration object.
1 <?php 2 3 4 namespace template_engine\element; 5 6 7 use template_engine\engine\TemplateEngine; 8 use util\text\variables\VariableResolver; 9 10 class PHPBlockElement extends HtmlElement 11 { 12 public $beforeBlock; 13 public $inBlock; 14 15 public function __construct() 16 { 17 parent::__construct( null ); 18 } 19 20 21 /** 22 * @param $format XMLFormatter 23 * @return string 24 */ 25 public function render($format ) 26 { 27 $content = $format->getIndentation(); 28 29 $content .= '<?php '.$this->beforeBlock.' { '.$this->inBlock.' ?>'; 30 31 $content .= $this->renderChildren( $format ); 32 33 $content .= $format->getIndentationOnClose(); 34 $content .= ' <?php } ?>'; 35 36 return $content; 37 } 38 39 40 41 42 43 public function textasvarname($value) 44 { 45 return $this->value($value); 46 } 47 48 49 public function varname($value) 50 { 51 return $this->value($value); 52 } 53 54 55 56 public static function value( $value ) 57 { 58 $res = new VariableResolver(); 59 $res->namespaceSeparator = ':'; 60 $res->renderOnlyVariables = true; 61 62 $res->addDefaultResolver( function($var) { 63 return '$'.$var; 64 } ); 65 66 $res->addResolver('config', function($name) { 67 $config_parts = explode('/', $name); 68 return TemplateEngine::OUTPUT_ALIAS.'::config([' . "'" . implode("'" . ',' . "'", $config_parts) . "'" . '])'; 69 }); 70 71 return $res->resolveVariables( $value ); 72 } 73 74 75 public function includeResource($file ) 76 { 77 return "include_once( 'modules/template_engine/components/html/component_".$file."');"; 78 } 79 80 }
Downloadmodules/template_engine/element/PHPBlockElement.class.php
History Sun, 1 Nov 2020 00:36:50 +0100 Jan Dankert Refactoring: Only using the configuration object. Sat, 17 Oct 2020 02:19:44 +0200 Jan Dankert Fix: Include of resources was broken since the last components refactoring. Sat, 3 Oct 2020 00:50:14 +0200 Jan Dankert Fix: Show the rights of node objects. Sat, 26 Sep 2020 04:26:55 +0200 Jan Dankert Refactoring: read configuration values with a class. Sat, 16 May 2020 01:08:40 +0200 Jan Dankert Refactoring: Switching the ValueExpressions in the templates to the new VariableResolver for supporting nested variables like ${message:prefix_${key}}. Sun, 23 Feb 2020 04:55:35 +0100 Jan Dankert New: Formatter for indenting XML files. Sat, 22 Feb 2020 01:58:20 +0100 Jan Dankert New: Autoloading of classes in all modules.