openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

ListComponent.class.php (789B)


      1 <?php
      2 
      3 namespace template_engine\components\html\component_list;
      4 
      5 use template_engine\components\html\Component;
      6 use template_engine\element\PHPBlockElement;
      7 
      8 class ListComponent extends Component
      9 {
     10 
     11 	public $list;
     12 
     13 	public $items;
     14 
     15 	public $extract = false;
     16 
     17 	public $key = 'list_key';
     18 
     19 	public $value = 'list_value';
     20 
     21 	public function createElement()
     22 	{
     23 		$list = new PHPBlockElement();
     24 
     25 		if   ( $this->items )
     26 			$listValue = '['.implode(',',array_map( function($value){return "'".$value."'";},explode(',',$this->items))).']';
     27 		else
     28 			$listValue = $list->value($this->list);
     29 
     30 		$list->beforeBlock = 'foreach((array)'.'@'.$listValue.' as $' . $this->key . '=>$' . $this->value . ')';
     31 
     32 		if ($this->extract)
     33 			$list->inBlock = 'extract($' . $this->value . ');';
     34 
     35 		return $list;
     36 	}
     37 
     38 }