-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPHPString.php
More file actions
32 lines (26 loc) · 991 Bytes
/
Copy pathPHPString.php
File metadata and controls
32 lines (26 loc) · 991 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
<?php declare(strict_types=1);
namespace Computator\FrameworkUtils\PHPTemplate\Templates;
use Computator\FrameworkUtils\PHPTemplate\TemplateRuntimeController;
/**
* PHP string literal template.
*
* Executes the provided literal string of PHP code as a template.
*/
class PHPString extends Base {
public readonly string $content;
public function __construct(string $content) {
$this->content = $content;
}
public function get_contents(int $offset = 0, ?int $length = null): string {
return substr($this->content, $offset, $length);
}
public function execute(array $context, mixed ...$controller_args): mixed {
$rc = new TemplateRuntimeController(...$controller_args);
return (function (...$__exec_args) {
extract($__exec_args['context']);
unset($__exec_args['context']);
// ending tag added to switch to HTML mode instead of starting in PHP mode
return eval("?>{$__exec_args['content']}");
})->call($rc, context: $context, content: $this->content);
}
}