openrat-cms

OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs | README

PHPBlockElement.class.php (1417B)


      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 }