File modules/template_engine/components/html/component_if/IfComponent.class.php

Last commit: Wed Oct 14 22:36:29 2020 +0200	Jan Dankert	Refactoring: Fixed the namespace in component classes, now the are able to be load by the standard autoloader.
1 <?php 2 3 namespace template_engine\components\html\component_if; 4 5 use template_engine\components\html\Component; 6 use template_engine\element\PHPBlockElement; 7 8 class IfComponent extends Component 9 { 10 public $true; 11 public $false; 12 public $contains; 13 public $value; 14 public $empty; 15 public $equals; 16 public $lessthan; 17 public $greaterthan; 18 public $present; 19 public $not; 20 21 22 public function createElement() 23 { 24 $if = new PHPBlockElement(); 25 26 $expr = '$if'.$this->getDepth().'='.(!isset($this->not)?'':'!').'('; 27 if ( $this->true ) 28 $expr .= $if->value($this->true); 29 elseif ($this->false) 30 $expr .= '!' . $if->value($this->false); 31 elseif ($this->contains) 32 $expr .= 'in_array('.$if->value($this->value).',explode(",",'.$if->value($this->contains).')'; 33 elseif ($this->equals) 34 $expr .= '' . $if->value($this->value).'==\''.$if->value($this->equals).'\''; 35 elseif ($this->lessthan) 36 $expr .= 'intval(' . $if->value($this->lessthan).')>intval('.$if->value($this->value).')'; 37 elseif ($this->greaterthan) 38 $expr .= 'intval(' . $if->value($this->greaterthan).')<count('.$if->value($this->value).')'; 39 elseif (! empty($this->present)) 40 $expr .= 'isset(' . '$'.$this->present.')'; // 'isset' verwenden! Nicht empty(), da false empty ist. 41 elseif (! empty($this->empty)) 42 $expr .= '(' . $if->value($this->empty).')==FALSE'; 43 elseif ($this->value) 44 $expr .= $if->value($this->value); 45 else 46 throw new \LogicException("Element 'if' has not enough parameters."); 47 $expr .= ');'; 48 49 $if->beforeBlock = $expr . ' if($if'.$this->getDepth().')'; 50 51 return $if; 52 } 53 }
Download modules/template_engine/components/html/component_if/IfComponent.class.php
History Wed, 14 Oct 2020 22:36:29 +0200 Jan Dankert Refactoring: Fixed the namespace in component classes, now the are able to be load by the standard autoloader. Wed, 14 Oct 2020 22:20:22 +0200 Jan Dankert Refactoring: Renamed component folders, because 'if' is no valid namespace fragment.