Skip to content

Commit 6c5a56b

Browse files
author
Wazabii
committed
Replace Format and traverse with new DTO lib
1 parent c8f85d5 commit 6c5a56b

File tree

14 files changed

+123
-1019
lines changed

14 files changed

+123
-1019
lines changed

Dom/Document.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class Document {
1515
"meta", "link", "img", "br", "hr", "input", "keygen", "param", "source", "track", "embed"
1616
];
1717

18-
private $html = "";
19-
private $elements;
18+
private $html;
19+
protected $elements;
2020
private $el;
2121

2222
private static $inst;
@@ -114,20 +114,27 @@ function getTag(string $key) {
114114
*/
115115
function execute(?callable $call = NULL) {
116116
$this->html = "";
117+
if(is_null($this->elements) && ($inst = $this->withElement())) $this->elements[] = $inst;
117118
if(is_array($this->elements)) {
118119
$this->build($this->elements, $call);
119120
}
120121
return $this->html;
121122
}
122123

123124
/**
124-
* Get get Dom/document (You need to execute first!)
125+
* Get get Dom/document (Will only trigger execute once per instance)
125126
* @return string
126127
*/
127128
function get() {
129+
if(is_null($this->html)) $this->execute();
128130
return $this->html;
129131
}
130132

133+
134+
function __toString() {
135+
return $this->get();
136+
}
137+
131138
/**
132139
* Build document
133140
* @param array $arr elements

Dom/Element.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use BadMethodCallException;
1313

14-
class Element extends Document{
14+
class Element extends Document {
1515

1616
private $inst;
1717
private $el;
@@ -27,6 +27,16 @@ function __construct(string $el, ?string $value, bool $snippet = false) {
2727
$this->value = $value;
2828
$this->snippet = $snippet;
2929
}
30+
31+
/**
32+
* Overwrite the current element
33+
* @param string $el HTML Tag name
34+
*/
35+
function setElement(string $el): self
36+
{
37+
$this->el = $el;
38+
return $this;
39+
}
3040

3141
/**
3242
* Set html attribute
@@ -45,10 +55,23 @@ function attr(string $key, ?string $val = NULL) {
4555
* @return self
4656
*/
4757
function attrArr(?array $arr) {
48-
$this->attr = array_merge($this->attr, $arr);
58+
if(is_array($arr)) $this->attr = array_merge($this->attr, $arr);
4959
return $this;
5060
}
5161

62+
function attrAddTo(string $key, string $value, string $sep = " ") {
63+
64+
65+
if(isset($this->attr[$key])) {
66+
$this->attr[$key] .= "{$sep}{$value}";
67+
} else {
68+
$this->attr[$key] = $value;
69+
}
70+
71+
return $this;
72+
}
73+
74+
5275
/**
5376
* Set el value <elem>[VALUE]</elem>
5477
* @param self
@@ -87,6 +110,13 @@ function buildAttr() {
87110
return $attr;
88111
}
89112

113+
function withElement() {
114+
if(!is_null($this->el)) {
115+
return clone $this;
116+
}
117+
return false;
118+
}
119+
90120

91121
/*
92122
function execute(?callable $call = NULL) {

Format/Arr.php

Lines changed: 0 additions & 88 deletions
This file was deleted.

Format/DateTime.php

Lines changed: 0 additions & 86 deletions
This file was deleted.

Format/FormatInterface.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

Format/Local.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)