Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| DashboardContents | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __toString | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace Apie\ApieBundle\Wrappers; |
| 3 | |
| 4 | use Apie\HtmlBuilders\ErrorHandler\CmsErrorRenderer; |
| 5 | use Apie\HtmlBuilders\ErrorHandler\StacktraceRenderer; |
| 6 | use Stringable; |
| 7 | use Throwable; |
| 8 | use Twig\Environment; |
| 9 | |
| 10 | class DashboardContents implements Stringable |
| 11 | { |
| 12 | public const NO_TWIG_MESSAGE = 'To configure the dashboard, you require to include symfony/twig-bundle...'; |
| 13 | |
| 14 | /** |
| 15 | * @param array<int|string, mixed> $templateParameters |
| 16 | */ |
| 17 | public function __construct( |
| 18 | private readonly ?Environment $twig, |
| 19 | private readonly string $twigTemplate, |
| 20 | private readonly array $templateParameters = [] |
| 21 | ) { |
| 22 | } |
| 23 | |
| 24 | public function __toString(): string |
| 25 | { |
| 26 | if ($this->twig === null) { |
| 27 | $fallback = self::NO_TWIG_MESSAGE; |
| 28 | // @see CmsErrorRenderer |
| 29 | if (($this->templateParameters['debugMode'] ?? null) && ($this->templateParameters['error'] ?? null) instanceof Throwable) { |
| 30 | $fallback = (string) new StacktraceRenderer($this->templateParameters['error']); |
| 31 | } |
| 32 | if (file_exists($this->twigTemplate)) { |
| 33 | return file_get_contents($this->twigTemplate) ? : $fallback; |
| 34 | } |
| 35 | return $fallback; |
| 36 | } |
| 37 | return $this->twig->render($this->twigTemplate, $this->templateParameters); |
| 38 | } |
| 39 | } |