13
13
14
14
class Compiler
15
15
{
16
+ protected const DOUBLE_CURLY_OPEN = '__DOUBLE_CURLY_OPEN__ ' ;
17
+ protected const DOUBLE_CURLY_CLOSE = '__DOUBLE_CURLY_CLOSE__ ' ;
18
+
16
19
/** @var String[] */
17
20
protected $ components ;
18
21
@@ -30,6 +33,8 @@ public function __construct(DOMDocument $document, LoggerInterface $logger)
30
33
$ this ->logger = $ logger ;
31
34
$ this ->document = $ document ;
32
35
$ this ->lastCloseIf = null ;
36
+
37
+ $ this ->logger ->debug ("\n--------- New Compiler Instance ---------- \n" );
33
38
}
34
39
35
40
/**
@@ -46,7 +51,7 @@ public function convert(): string
46
51
$ rootNode = $ this ->getRootNode ($ templateElement );
47
52
$ resultNode = $ this ->convertNode ($ rootNode );
48
53
49
- return $ this ->document ->saveHTML ($ resultNode );
54
+ return $ this ->replacePlaceholders ( $ this -> document ->saveHTML ($ resultNode) );
50
55
}
51
56
52
57
public function convertNode (DOMNode $ node ): DOMNode
@@ -95,7 +100,7 @@ private function handleAttributeBinding(DOMElement $node)
95
100
continue ;
96
101
}
97
102
98
- $ name = substr ($ attribute ->name , 1 );
103
+ $ name = substr ($ attribute ->name , strpos ( $ attribute -> name , ' : ' ) + 1 );
99
104
$ value = $ attribute ->value ;
100
105
$ this ->logger ->debug ('- handle: ' . $ name . ' = ' . $ value );
101
106
@@ -110,17 +115,18 @@ private function handleAttributeBinding(DOMElement $node)
110
115
break ;
111
116
default :
112
117
if ($ value === 'true ' ) {
118
+ $ this ->logger ->debug ('- setAttribute ' .$ name );
113
119
$ node ->setAttribute ($ name , $ name );
120
+ } else {
121
+ $ this ->logger ->debug ('- setAttribute " ' .$ name .'" with value ' );
122
+ $ node ->setAttribute (
123
+ $ name ,
124
+ self ::DOUBLE_CURLY_OPEN .$ value .self ::DOUBLE_CURLY_CLOSE
125
+ );
114
126
}
115
- $ node ->setAttribute ($ name , $ value );
116
127
}
117
128
118
- if (is_bool ($ value )) {
119
- if ($ value ) {
120
- $ this ->logger ->debug ('=> setAttribute ' );
121
- $ node ->setAttribute ($ name , $ name );
122
- }
123
- } elseif (is_array ($ value )) {
129
+ if (is_array ($ value )) {
124
130
if ($ name === 'style ' ) {
125
131
$ styles = [];
126
132
foreach ($ value as $ prop => $ setting ) {
@@ -141,7 +147,7 @@ private function handleAttributeBinding(DOMElement $node)
141
147
}
142
148
}
143
149
144
- $ this ->logger ->debug ('=> remove ' . $ attribute ->name );
150
+ $ this ->logger ->debug ('=> remove original ' . $ attribute ->name );
145
151
$ node ->removeAttribute ($ attribute ->name );
146
152
}
147
153
}
@@ -251,11 +257,6 @@ private function stripEventHandlers(DOMElement $node)
251
257
}
252
258
}
253
259
254
- private function isTextNode (DOMNode $ node ): bool
255
- {
256
- return $ node instanceof DOMCharacterData;
257
- }
258
-
259
260
/**
260
261
* @throws Exception
261
262
*/
@@ -282,4 +283,12 @@ private function getRootNode(DOMElement $element): \DOMNode
282
283
283
284
return $ firstTagNode ;
284
285
}
286
+
287
+ protected function replacePlaceholders (string $ string )
288
+ {
289
+ $ string = str_replace (self ::DOUBLE_CURLY_OPEN , '{{ ' , $ string );
290
+ $ string = str_replace (self ::DOUBLE_CURLY_CLOSE , '}} ' , $ string );
291
+
292
+ return $ string ;
293
+ }
285
294
}
0 commit comments