4
4
5
5
namespace Atk4 \Ui ;
6
6
7
- use Atk4 \Core \AppScopeTrait ;
8
7
use Atk4 \Core \WarnDynamicPropertyTrait ;
9
- use Atk4 \Data \Model ;
10
8
use Atk4 \Ui \HtmlTemplate \TagTree ;
11
9
use Atk4 \Ui \HtmlTemplate \Value as HtmlValue ;
12
10
15
13
*/
16
14
class HtmlTemplate
17
15
{
18
- use AppScopeTrait;
19
16
use WarnDynamicPropertyTrait;
20
17
21
18
public const TOP_TAG = '_top ' ;
@@ -107,10 +104,6 @@ public function cloneRegion(string $tag): self
107
104
// TODO prune unreachable nodes
108
105
// $template->rebuildTagsIndex();
109
106
110
- if ($ this ->issetApp ()) {
111
- $ template ->setApp ($ this ->getApp ());
112
- }
113
-
114
107
return $ template ;
115
108
}
116
109
@@ -141,31 +134,13 @@ protected function emptyTagTree(TagTree $tagTree): void
141
134
*
142
135
* If tag contains another tag trees, these tag trees are emptied.
143
136
*
144
- * @param string|array<string, string>|Model $tag
145
- * @param ($tag is array|Model ? never : string|null) $value
137
+ * @param string|array<string, string> $tag
138
+ * @param ($tag is array ? never : string|null) $value
146
139
*/
147
140
protected function _setOrAppend ($ tag , string $ value = null , bool $ encodeHtml = true , bool $ append = false , bool $ throwIfNotFound = true ): void
148
141
{
149
- if ($ tag instanceof Model && $ value === null ) {
150
- if (!$ encodeHtml ) {
151
- throw new Exception ('HTML is not allowed to be dangerously set from Model ' );
152
- }
153
-
154
- // $tag passed as model
155
- // in this case we don't throw exception if tags don't exist
156
- $ uiPersistence = $ this ->getApp ()->uiPersistence ;
157
- foreach ($ tag ->getFields () as $ k => $ field ) {
158
- if ($ this ->_hasTag ($ k )) {
159
- $ v = $ uiPersistence ->typecastSaveField ($ field , $ tag ->get ($ k ));
160
- $ this ->_setOrAppend ($ k , $ v , $ encodeHtml , $ append );
161
- }
162
- }
163
-
164
- return ;
165
- }
166
-
167
142
// $tag passed as associative array [tag => value]
168
- if (is_array ($ tag ) && $ value === null ) {
143
+ if (is_array ($ tag ) && $ value === null ) { // @phpstan-ignore-line
169
144
if ($ throwIfNotFound ) {
170
145
foreach ($ tag as $ k => $ v ) {
171
146
if (!$ this ->_hasTag ($ k )) {
@@ -182,7 +157,7 @@ protected function _setOrAppend($tag, string $value = null, bool $encodeHtml = t
182
157
}
183
158
184
159
if (!is_string ($ tag ) || $ tag === '' ) {
185
- throw (new Exception ('Tag must be non-empty string ' ))
160
+ throw (new Exception ('Tag must be ' . ( is_string ( $ tag ) ? ' non-empty ' : '' ) . ' string ' ))
186
161
->addMoreInfo ('tag ' , $ tag )
187
162
->addMoreInfo ('value ' , $ value );
188
163
}
@@ -216,8 +191,8 @@ protected function _setOrAppend($tag, string $value = null, bool $encodeHtml = t
216
191
* If tag is found inside template several times, all occurrences are
217
192
* replaced.
218
193
*
219
- * @param string|array<string, string>|Model $tag
220
- * @param ($tag is array|Model ? never : string|null) $value
194
+ * @param string|array<string, string> $tag
195
+ * @param ($tag is array ? never : string|null) $value
221
196
*
222
197
* @return $this
223
198
*/
@@ -232,8 +207,8 @@ public function set($tag, string $value = null): self
232
207
* Same as set(), but won't generate exception for non-existing
233
208
* $tag.
234
209
*
235
- * @param string|array<string, string>|Model $tag
236
- * @param ($tag is array|Model ? never : string|null) $value
210
+ * @param string|array<string, string> $tag
211
+ * @param ($tag is array ? never : string|null) $value
237
212
*
238
213
* @return $this
239
214
*/
@@ -248,8 +223,8 @@ public function trySet($tag, string $value = null): self
248
223
* Set value of a tag to a HTML content. The value is set without
249
224
* encoding, so you must be sure to sanitize.
250
225
*
251
- * @param string|array<string, string>|Model $tag
252
- * @param ($tag is array|Model ? never : string|null) $value
226
+ * @param string|array<string, string> $tag
227
+ * @param ($tag is array ? never : string|null) $value
253
228
*
254
229
* @return $this
255
230
*/
@@ -264,8 +239,8 @@ public function dangerouslySetHtml($tag, string $value = null): self
264
239
* See dangerouslySetHtml() but won't generate exception for non-existing
265
240
* $tag.
266
241
*
267
- * @param string|array<string, string>|Model $tag
268
- * @param ($tag is array|Model ? never : string|null) $value
242
+ * @param string|array<string, string> $tag
243
+ * @param ($tag is array ? never : string|null) $value
269
244
*
270
245
* @return $this
271
246
*/
@@ -279,8 +254,8 @@ public function tryDangerouslySetHtml($tag, string $value = null): self
279
254
/**
280
255
* Add more content inside a tag.
281
256
*
282
- * @param string|array<string, string>|Model $tag
283
- * @param ($tag is array|Model ? never : string|null) $value
257
+ * @param string|array<string, string> $tag
258
+ * @param ($tag is array ? never : string|null) $value
284
259
*
285
260
* @return $this
286
261
*/
@@ -295,8 +270,8 @@ public function append($tag, ?string $value): self
295
270
* Same as append(), but won't generate exception for non-existing
296
271
* $tag.
297
272
*
298
- * @param string|array<string, string>|Model $tag
299
- * @param ($tag is array|Model ? never : string|null) $value
273
+ * @param string|array<string, string> $tag
274
+ * @param ($tag is array ? never : string|null) $value
300
275
*
301
276
* @return $this
302
277
*/
@@ -311,8 +286,8 @@ public function tryAppend($tag, ?string $value): self
311
286
* Add more content inside a tag. The content is appended without
312
287
* encoding, so you must be sure to sanitize.
313
288
*
314
- * @param string|array<string, string>|Model $tag
315
- * @param ($tag is array|Model ? never : string|null) $value
289
+ * @param string|array<string, string> $tag
290
+ * @param ($tag is array ? never : string|null) $value
316
291
*
317
292
* @return $this
318
293
*/
@@ -327,8 +302,8 @@ public function dangerouslyAppendHtml($tag, ?string $value): self
327
302
* Same as dangerouslyAppendHtml(), but won't generate exception for non-existing
328
303
* $tag.
329
304
*
330
- * @param string|array<string, string>|Model $tag
331
- * @param ($tag is array|Model ? never : string|null) $value
305
+ * @param string|array<string, string> $tag
306
+ * @param ($tag is array ? never : string|null) $value
332
307
*
333
308
* @return $this
334
309
*/
0 commit comments