-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Runtime.php
40 lines (32 loc) · 984 Bytes
/
Runtime.php
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
39
40
<?php
declare(strict_types=1);
namespace Setono\EditorJSBundle\Twig;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Setono\EditorJS\Parser\ParserInterface;
use Setono\EditorJS\Renderer\RendererInterface;
use Twig\Extension\RuntimeExtensionInterface;
final class Runtime implements RuntimeExtensionInterface, LoggerAwareInterface
{
private LoggerInterface $logger;
public function __construct(
private readonly ParserInterface $parser,
private readonly RendererInterface $renderer,
) {
$this->logger = new NullLogger();
}
public function render(string $json): string
{
try {
return $this->renderer->render($this->parser->parse($json));
} catch (\Throwable $e) {
$this->logger->error($e->getMessage());
}
return '';
}
public function setLogger(LoggerInterface $logger): void
{
$this->logger = $logger;
}
}