openrat-cms

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

Element.class.php (936B)


      1 <?php
      2 
      3 
      4 namespace modules\template_engine;
      5 
      6 
      7 class Element
      8 {
      9 	private $name;
     10 	private $attributes = [];
     11 	private $content    = '';
     12 	private $selfClosing    = true;
     13 
     14 	public function __construct( $name )
     15 	{
     16 		$this->name = $name;
     17 	}
     18 
     19 	public function content( $content )
     20 	{
     21 		$this->content = $content;
     22 		return $this;
     23 	}
     24 
     25 	public function getBegin() {
     26 
     27 		return '<'.$this->name.array_reduce( array_keys($this->attributes),function($carry,$key){return $carry.' '.$key.'="'.htmlspecialchars($this->attributes[$key]).'"';},'').(($this->selfClosing && !$this->content)?' /':'').'>'.$this->content;
     28 	}
     29 
     30 
     31 	public function getEnd() {
     32 		if   ( $this->selfClosing && !$this->content)
     33 			return '';
     34 		else
     35 			return '</'.$this->name.'>';
     36 	}
     37 
     38 	public function attr($key,$value) {
     39 		$this->attributes[$key] = $value;
     40 		return $this;
     41 	}
     42 
     43 	public function selfClosing($selfClosing) {
     44 		$this->selfClosing = boolval($selfClosing);
     45 		return $this;
     46 	}
     47 }