@@ -19,6 +19,7 @@ class Element extends Document {
1919 private $ snippet ;
2020 private $ value ;
2121 private $ node ;
22+ private $ hideEmptyTag = false ;
2223
2324
2425 function __construct (string $ el , ?string $ value , bool $ snippet = false ) {
@@ -59,24 +60,55 @@ function attrArr(?array $arr) {
5960 return $ this ;
6061 }
6162
62- function attrAddTo (string $ key , string $ value , string $ sep = " " ) {
63-
63+ /**
64+ * Hide html tag if its value is empty
65+ * @param bool $bool
66+ * @return self
67+ */
68+ function hideEmptyTag (bool $ bool ): self
69+ {
70+ $ this ->hideEmptyTag = $ bool ;
71+ return $ this ;
72+ }
6473
74+ /**
75+ * Validate hide tag value
76+ * @return bool
77+ */
78+ protected function hideTagValid (): bool
79+ {
80+ return (bool )(($ this ->hideEmptyTag && !$ this ->value ));
81+ }
82+
83+ /**
84+ * Add value to attr
85+ * @param string $key
86+ * @param string $value
87+ * @param string $sep
88+ * @return self
89+ */
90+ function attrAdd (string $ key , string $ value , string $ sep = " " ): self
91+ {
6592 if (isset ($ this ->attr [$ key ])) {
6693 $ this ->attr [$ key ] .= "{$ sep }{$ value }" ;
6794 } else {
6895 $ this ->attr [$ key ] = $ value ;
6996 }
70-
7197 return $ this ;
7298 }
73-
99+
100+ // Same as above
101+ function attrAddTo (string $ key , string $ value , string $ sep = " " ): self
102+ {
103+ return $ this ->attrAdd ($ key , $ value , $ sep );
104+ }
74105
75106 /**
76107 * Set el value <elem>[VALUE]</elem>
77108 * @param self
78109 */
79- function setValue (?string $ value ) {
110+ function setValue (?string $ value ): self
111+ {
80112 $ this ->value = $ value ;
81113 return $ this ;
82114 }
@@ -85,23 +117,26 @@ function setValue(?string $value) {
85117 * Set el value
86118 * @param string
87119 */
88- function getValue () {
89- return $ this ->value ;
120+ function getValue (): string
121+ {
122+ return (string )$ this ->value ;
90123 }
91124
92125 /**
93126 * Get el/HTML tag
94- * @return [type] [description]
127+ * @return string
95128 */
96- function getEl () {
97- return $ this ->el ;
129+ function getEl (): string
130+ {
131+ return (string )$ this ->el ;
98132 }
99133
100134 /**
101135 * Array attr to string
102136 * @return string
103137 */
104- function buildAttr () {
138+ protected function buildAttr (): string
139+ {
105140 $ attr = "" ;
106141 if (count ($ this ->attr ) > 0 ) foreach ($ this ->attr as $ k => $ v ) {
107142 $ attr .= " {$ k }" ;
@@ -110,7 +145,12 @@ function buildAttr() {
110145 return $ attr ;
111146 }
112147
113- function withElement () {
148+ /**
149+ * Clone/Static
150+ * @return static|false
151+ */
152+ function withElement ()
153+ {
114154 if (!is_null ($ this ->el )) {
115155 return clone $ this ;
116156 }
0 commit comments