-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile.php
More file actions
32 lines (26 loc) · 1.1 KB
/
Copy pathFile.php
File metadata and controls
32 lines (26 loc) · 1.1 KB
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\Exceptions;
use Computator\FrameworkUtils\PHPTemplate\TemplateRuntimeController;
class File extends Base {
public readonly string $path;
public function __construct(string $path) {
if ($path == '' || !is_readable($path))
throw new Exceptions\TemplateNotFoundException("template '{$path}' does not exist or is not readable");
$this->path = $path;
}
public function get_contents(int $offset = 0, ?int $length = null): string {
$rv = @file_get_contents($this->path, offset: $offset, length: $length);
if ($rv === false)
throw new Exceptions\TemplateRenderException("error reading template file '{$this->path}'");
return $rv;
}
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']);
return include $__exec_args['path'];
})->call($rc, context: $context, path: $this->path);
}
}