summaryrefslogtreecommitdiff
path: root/src/View.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/View.php')
-rw-r--r--src/View.php37
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);
+ }
+}