Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
TemplateRenderProxy
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 with
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 __invoke
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php declare(strict_types=1);
2
3namespace Computator\FrameworkUtils\PHPTemplate\RenderObjects;
4
5use Computator\FrameworkUtils\PHPTemplate\Exceptions;
6use Computator\FrameworkUtils\PHPTemplate\Templates;
7use Computator\FrameworkUtils\PHPTemplate\UserApi;
8use Computator\FrameworkUtils\PHPTemplate\Utils;
9use ValueError;
10
11class TemplateRenderProxy implements UserApi\ResolvedTemplateClient {
12    protected static int $next_id = 1;
13    public readonly int $id;
14
15    /** @var array<string,mixed> $context */
16    protected array $context = [];
17
18    public function __construct(
19        protected readonly UserApi\RenderManager $renderer,
20        protected readonly Templates\Base $tpl,
21    ) {
22        $this->id = self::$next_id++;
23    }
24
25    public function with(mixed ...$context): self {
26        try {
27            $this->context = Utils::transform_context($context);
28        } catch (ValueError $e) {
29            throw new Exceptions\TemplateLogicException("'".__FUNCTION__."' called using invalid data format: $e", previous: $e);
30        }
31        return $this;
32    }
33
34    public function __invoke(): void {
35        $this->renderer->renderProxiedTemplate($this, $this->context);
36    }
37}