-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJsonToHtml.php
More file actions
38 lines (27 loc) · 587 Bytes
/
JsonToHtml.php
File metadata and controls
38 lines (27 loc) · 587 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php declare(strict_types=1);
namespace h4kuna\DataType\Collection;
use Nette\Utils\Html;
use Nette\Utils\Json;
use Stringable;
abstract class JsonToHtml implements Stringable
{
public function __construct(private string $_id)
{
}
public function __toString(): string
{
return (string) $this->render();
}
public function render(): ?Html
{
$config = get_object_vars($this);
unset($config['_id']);
if ($config === []) {
return null;
}
$el = Html::el('script', Json::encode($config));
$el->type = 'text/json';
$el->id = $this->_id;
return $el;
}
}