init
This commit is contained in:
45
src/Core/Kernel/Templating.php
Normal file
45
src/Core/Kernel/Templating.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user