Files
framework/src/Core/Kernel/Templating.php
Gregory Letellier 13c80f5642 init
2023-11-14 11:18:23 +01:00

46 lines
1.1 KiB
PHP

<?php
namespace Kletellier\MiniWeb\Core\Kernel;
use eftec\bladeone\BladeOne;
class Templating
{
private $_views;
private $_cache;
private static $_instance = null;
private ?BladeOne $_blade = null;
private $_root;
private function __construct()
{
$this->_root = Container::get("ROOT");
$this->_views = $this->_root . DIRECTORY_SEPARATOR . "views";
$this->_cache = $this->_root . DIRECTORY_SEPARATOR . "cache";
$mode = ($this->isDebug()) ? BladeOne::MODE_AUTO : BladeOne::MODE_FAST;
$this->_blade = new BladeOne($this->_views, $this->_cache, $mode);
}
public static function getInstance()
{
if (self::$_instance == null) {
self::$_instance = new Templating();
}
return self::$_instance;
}
private function isDebug(): bool
{
$ret = true;
if (isset($_ENV["DEBUG"])) {
$ret = ($_ENV["DEBUG"] == "true");
}
return $ret;
}
public function render(string $template, array $params = []): string
{
return $this->_blade->run($template, $params);
}
}