tagName = $tagName; $this->props = $props; $this->childrens = $childrens; } function __toString() { return '<' . $this->tagName . $this->attributesToString() . '>' . $this->childrensToString() . 'tagName . '>'; } function toReactNode() { // @return array(3): [ tagName, attributes, childrens ] @see p5UI__buildDom return [ (string)$this->tagName, !$this->props ? [] : $this->props, $this->childrensToReactNodes(), ]; } // 'reactNode' => [ 'div', [ 'class' => "container AjaxFrmHorizontalEdit", 'style' => [ "max-width" => "940px" ] ], [ // [ 'h4', [ 'style' => [ "padding-bottom" => "3px", "border-bottom" => "1px solid #ddd" ] ], [ // "Edycja rekordu Nr {$record['ID']}", // [ 'small', [ 'class' => "pull-right valign-btns-bottom" ], [ $rowFunctionsOut ] ], // ] ], // [ 'P5UI__FeatureEditForm', [ // 'class' => "", 'action' => "", 'method' => "post", // 'id' => "EDIT_FRM_{$this->_htmlID}", // TODO: rm - use React nodes // TODO: $this->_htmlID not exists! // 'ajaxSaveUrl' => "{$syncUrl}&_task=editSaveAjax", // TODO:? &_hash={$this->_htmlID} // 'namespace' => $acl->getNamespace(), // 'idRecord' => $record['ID'], // 'tableLabelHtml' => $tblLabel, // ], [ // [ 'fieldset', [ 'style' => [ "padding-bottom" => "100px" ] ], $jsFields ] // fieldset // ] ] // form // ] ] // .container function attributesToString() { if (!$this->props) return ''; $attrs = ''; foreach ($this->props as $k => $v) { if (is_array($v)) { $attrs .= " {$k}=\"" . implode(" ", $v) . "\""; } else if (true === $v) { // eg. open => true : 'open' $attrs .= " {$k}"; } else if (false === $v) { // skip if false value } else if (!empty($v)) { $attrs .= " {$k}=\"{$v}\""; } } return $attrs; } function scalarChildToString($child) { if (null === $child) return ''; if (is_scalar($child)) { if (is_float($child) && !$child) return '0.0'; // TODO: is price -> '0.00' // if (is_null($child)) return 'NULL'; // ?? return (string)$child; } } function childrensToReactNodes() { if (null === $this->childrens) return ''; if (is_scalar($this->childrens)) return $this->scalarChildToString($this->childrens); if (is_object($this->childrens) && $this->childrens instanceof UI_Node) return [ $this->childrens->toReactNode() ]; if (!is_array($this->childrens)) throw new Exception("Unsupported children type"); return array_map( function ($child) { if (null === $child) return null; if (is_scalar($child)) return $this->scalarChildToString($child); if (is_object($child)) return $child->toReactNode(); // TODO: is class UI_Node return (string)$child; // or throw new Exception('Not implemented UI_Node child type'); }, $this->childrens ); } function childrensToString() { if (null === $this->childrens) return ''; if (is_scalar($this->childrens)) return $this->scalarChildToString($this->childrens); if (is_object($this->childrens) && $this->childrens instanceof UI_Node) return (string)$this->childrens; // if (!is_array($this->childrens)) throw new Exception("Unsupported children type"); if (!is_array($this->childrens)) trigger_error("Unsupported children type: " . var_export($this->childrens, true), E_USER_WARNING); if (!is_array($this->childrens)) return ''; return array_reduce( $this->childrens, function ($ret, $child) { return "{$ret}{$child}"; // $child->__toString() }, "" ); } }