SetComponent.class.php (739B)
1 <?php 2 3 namespace template_engine\components\html\component_set; 4 5 use template_engine\components\html\Component; 6 use template_engine\element\PHPBlockElement; 7 use template_engine\element\Value; 8 9 class SetComponent extends Component 10 { 11 public $var; 12 public $value; 13 public $key; 14 15 16 public function createElement() 17 { 18 $set = new PHPBlockElement(); 19 20 if ($this->value) 21 { 22 if ($this->key) 23 $set->inBlock = '$'.$set->varname($this->var).'= '.$set->value($this->value).'['.((new Value($this->key))->render(Value::CONTEXT_PHP)).'];'; 24 else 25 $set->inBlock = '$'.$set->varname($this->var).'= '.$set->value($this->value).';'; 26 } 27 else { 28 // Unset 29 $set->inBlock = 'unset($'.$set->varname($this->var).')'; 30 } 31 32 return $set; 33 } 34 }