_properties = Util::toObject($properties); } public function __get($name) { if (isset($this->_properties->{$name})) { return $this->_properties->{$name}; } throw new \Exception('Undefined property: '.$name); } public function __set($name, $value) { if (isset($this->_properties->{$name})) { $this->_properties->{$name} = $value; return; } throw new \Exception('Undefined property: '.$name); } public function __call($name, $args) { if (property_exists($this->_properties, $name)) { if (!$args) return $this->_properties->{$name}; $value = null; $key = null; if (count($args) > 1 && is_array($this->_properties->{$name})) { $key = $args[0]; $value = $args[1]; if (!is_string($key) && !is_int($key)) { throw new \Exception('UI property: '.$name.' must be string or int.'); } $this->_properties->{$name}[$key] = $value; if (isset($args[2]) && Helper::isClosure($args[2])) { //process callback $callback = $args[2]; Helper::runCallback($callback, [$this]); } return $this; } else { if (isset($args[1]) && Helper::isClosure($args[1])) { $value = $args[0]; $this->_properties->{$name} = $value; $callback = $args[1]; Helper::runCallback($callback, [$this]); return $this; } else if (is_array($this->_properties->{$name}) && (is_string($args[0]) || is_int($args[0]))) { $key = $args[0]; if (!is_string($key) && !is_int($key)) { throw new \Exception('UI property key: '.$key.' must be string or int.'); } return $this->_properties->{$name}[$key]; } else { $value = $args[0]; $this->_properties->{$name} = $value; return $this; } } } throw new \Exception('Undefined property: '.$name); } protected function getPropValue($prop, $methods = null) { if (!$methods) { $methods = [ 'if_closure' => function($prop) { return Helper::runCallback($prop, [$this]); }, 'if_array' => function($prop) { throw new \Exception(get_called_class().':property requires string'); } ]; } return Helper::getValue($prop, $methods); } protected function getPropValueAttr($prop, $data = null) { return Helper::getValue($prop, [ 'if_closure' => function($attr) { $callback_return = Helper::runCallback($attr, [$this]); if (is_array($callback_return)) return $callback_return; else return [$callback_return]; }, 'if_array' => function($attr) use ($data) { $attrs = Helper::attrs($attr, $data); return [$attrs]; }, 'if_other' => function($attr) { return [$attr]; } ]); } public static function printList($items, $options = [], $return = false) { $items_html = ''; $main_attrs = []; $defaults = [ 'type' => 'ul', 'attr' => [], 'class' => [], 'id' => '' ]; $options = Util::setValues($defaults, $options, 'class'); foreach ($items as $item) { $item_html = ''; $item_prop = [ 'content' => '', 'subitems' => [], 'class' => '', 'attr' => [] ]; $new_item_prop = Helper::getProps($item_prop, $item, [$item], 'content'); $content = $new_item_prop['content']; if ($new_item_prop['subitems']) { $content .= self::printList($new_item_prop['subitems'], false, true); } $attrs = []; if ($new_item_prop['class']) $attrs[] = 'class="'.(is_array($new_item_prop['class']) ? implode(' ', $new_item_prop['class']) : $new_item_prop['class']).'"'; if ($new_item_prop['attr']) { foreach ($new_item_prop['attr'] as $key => $value) { $attrs[] = $key.'="'.$value.'"'; } } $item_html = '