blob: 7862b12ba8d1aa65b57b7b7c91a922bf077fac2e (
plain)
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
|
<?php
namespace App;
use Twig\Environment;
use Twig\Extension\DebugExtension;
use Twig\Loader\FilesystemLoader;
use Twig\TwigFilter;
class View
{
private static Environment $twig;
public static function init(): void
{
$loader = new FilesystemLoader(dirname(__DIR__) . '/views');
self::$twig = new Environment($loader, [
'debug' => $_ENV['APP_ENV'] === 'development',
]);
self::$twig->addExtension(new DebugExtension());
// self::$twig->addExtension(new IntlExtension());
self::$twig->addFilter(new TwigFilter('buildTime', function ($buildTime) {
return @sprintf('%02d:%02d:%02d', $buildTime / 3600, ($buildTime / 60) % 60, $buildTime % 60);
}));
self::$twig->addGlobal('session', $_SESSION);
}
/**
* @param string $name
* @param array $context
*/
public static function render(string $name, array $context = []): string
{
return self::$twig->render($name, $context);
}
}
|