diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-09-24 13:40:25 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-09-24 13:40:25 +0200 |
commit | fa00b957378a393f8edbfc98ef111d35d18ecb09 (patch) | |
tree | 654e7dc5414f7f2795dbe996d3e1570793a5b1b8 /src/View.php |
initial commit
Diffstat (limited to 'src/View.php')
-rw-r--r-- | src/View.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/View.php b/src/View.php new file mode 100644 index 0000000..5f9ca34 --- /dev/null +++ b/src/View.php @@ -0,0 +1,37 @@ +<?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); + })); + } + + /** + * @param string $name + * @param array $context + */ + public static function render(string $name, array $context = []): string + { + return self::$twig->render($name, $context); + } +} |