htmlComment ) ) $this->htmlComment->add( $strComment ); else { if ( is_null( $this->cacheLog ) ) $this->cacheLog = array(); $this->cacheLog[]=$strComment; } } protected function enableLog( ) : void { if ( is_null( $this->htmlComment ) ) { $this->htmlComment = new Comment(); $this->contents[]= $this->htmlComment; } if ( is_array( $this->cacheLog ) ) { foreach( $this->cacheLog as $strComment ) $this->addLog( $strComment ); unset( $this->cacheLog ); $this->cacheLog=null; } } private $contents = array(); private $params = array(); public $balise = ""; public $emptyClosable = false; public $emptyWithOutClose = false; public $noIndent = false; public function __construct( string $baliseName = "div", array $params = null ) { parent::__construct(); $this->balise = $baliseName; if ( ! is_null( $params ) ) $this->addParams($params); } ///* public function DwSerializableInit() { parent::DwSerializableInit(); $this->addtoSerialize("balise"); $this->addtoSerialize("emptyClosable"); $this->addtoSerialize("emptyWithOutClose"); $this->addtoSerialize("noIndent"); } //*/ public function clear() : void { $this->contents = array(); $this->params = array(); if ( is_object( $this->htmlComment ) ) $this->contents[]= $this->htmlComment; } public function noIndent() : void { $this->noIndent = true; } public function emptyClosable() : void { $this->emptyClosable = true; } public function emptyWithOutClose() : void { $this->emptyClosable(); $this->emptyWithOutClose = true; } private function objectToXml( object $content ,int $nbSpace, array &$parents = null ) { $html=""; if ( \method_exists( $content ,'__toXml' ) ) $html.= $content->__toXml( $nbSpace ,$parents ); elseif ( \method_exists( $content ,'toString' ) ) $html.= $content->toString(); else $html.= $content; return $html; } public function add($content) : void { //if ( $this->checkParent( ) ) $this->contents[]=$content; } /* private function checkParent ( array &$parents = null ) : bool { } //*/ public function __toXml( int $nbSpace = 0 ,array &$parents = null ) : string { $html = ""; ///* if ( is_null( $parents ) ) $parents = array(); $found = false; if ( ( $found = array_search( $this ,$parents ,true ) ) != false ) { throw new \Exception( "Parent Object Looping found[{$found}]\r\n" .$this->getClassName()."/".$this->getInstanceKey()."\r\n" .$this ."\r\n===============\r\n" .$parents[$found]->getClassName()."/".$parents[$found]->getInstanceKey()."\r\n" .$parents[$found] ); } $parents[] = $this; //*/ $mySpace="";for($cpt=0;!$this->noIndent && $cpt<$nbSpace;$cpt++) $mySpace.=" "; $myReturnLine = $this->noIndent ? "" : "\r\n" ; $html = "<{$this->balise}"; if ( is_array( $this->params ) && ! empty( $this->params ) ) { $html.=" "; foreach ($this->params as $key => $value) $html.= "$key=\"$value\" "; } if (empty($this->contents)) { if ( $this->emptyClosable ) if ( $this->emptyWithOutClose ) $html.= ">"; else $html.= "/>"; else $html.= ">balise}>"; } else { $html.= ">".$myReturnLine; foreach ($this->contents as $content) { $subParents = $parents; if ( is_array( $content ) ) { foreach( $content as $subContent ) { $html.= $mySpace.( $this->noIndent ? "" : " " ); if ( is_object($subContent) ) $html.= $this->objectToXml( $subContent ,$nbSpace + 1 ,$subParents ); else $html.= $subContent; $html.=$myReturnLine; } }else { $html.= $mySpace.( $this->noIndent ? "" : " " ); if ( is_object($content) ) $html.= $this->objectToXml( $content ,$nbSpace + 1 ,$subParents ); else $html.= $content; $html.=$myReturnLine; } } $html.= $mySpace."balise}>"; } return $html; } public function toString( $withParent = false ) : string { return $this->__toXml(); } public function addParams( array $params ) : bool { return $this->setParams($params); } public function setParams( array $params ) : bool { $return = true; foreach($params as $key => $value) { if ( is_null( $value ) ) $return&=$this->unsetParam( $key ); else $return&=$this->setParam($key, $value); } return $return; } public function unsetParam( string $key ) : bool { $return = isset( $this->params[$key] ); if ( $return ) unset( $this->params[$key] ); return $return; } public function setParam( string $key, $value) : bool { $return = true; $this->params[$key] = $value; return $return; } public function getParam($key) { return isset($this->params[$key]) ? $this->params[$key] : null; } public function getClassName( bool $fqcn=null ) : string { return self::getStaticClassName( $fqcn ); } public static function getStaticClassName( bool $fqcn=null ) : string { return $fqcn ? parent::getStaticClassName( $fqcn ).self::CLASS_SEPARATOR.__CLASS__ : __CLASS__; } }