Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
PHPString
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
3 / 3
3
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
 get_contents
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php declare(strict_types=1);
2
3namespace Computator\FrameworkUtils\PHPTemplate\Templates;
4
5use Computator\FrameworkUtils\PHPTemplate\TemplateRuntimeController;
6
7/**
8 * PHP string literal template.
9 *
10 * Executes the provided literal string of PHP code as a template.
11 */
12class PHPString extends Base {
13    public readonly string $content;
14
15    public function __construct(string $content) {
16        $this->content = $content;
17    }
18
19    public function get_contents(int $offset = 0, ?int $length = null): string {
20        return substr($this->content, $offset, $length);
21    }
22
23    public function execute(array $context, mixed ...$controller_args): mixed {
24        $rc = new TemplateRuntimeController(...$controller_args);
25        return (function (...$__exec_args) {
26            extract($__exec_args['context']);
27            unset($__exec_args['context']);
28            // ending tag added to switch to HTML mode instead of starting in PHP mode
29            return eval("?>{$__exec_args['content']}");
30        })->call($rc, context: $context, content: $this->content);
31    }
32}