-
Notifications
You must be signed in to change notification settings - Fork 1
/
Template.php
52 lines (42 loc) · 1.1 KB
/
Template.php
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace Neoan3\Apps\Template;
class Template
{
/**
* @param string $content
* @param array $contextData
*
* @return string
*/
static function embrace(string $content, array $contextData): string
{
$interpreter = new Interpreter($content, $contextData);
self::ensureDefaults();
return $interpreter->asHtml();
}
/**
* @param $location
* @param $array
*
* @return string
*/
static function embraceFromFile($location, $array): string
{
$file = file_get_contents(Constants::getPath() . '/' . $location);
return self::embrace($file, $array);
}
public static function ensureDefaults():void
{
// onboard attributes
$registered = Constants::getCustomAttributes();
$needed = [
'n-for' => Attributes\NFor::class,
'n-if' => Attributes\NIf::class
];
foreach ($needed as $name => $class){
if(!isset($registered[$name])){
Constants::addCustomAttribute($name, new $class());
}
}
}
}