63 lines
1.5 KiB
PHP
63 lines
1.5 KiB
PHP
<?php
|
|
namespace App\Helpers;
|
|
|
|
use App\Models\Module;
|
|
use DebugBar\Bridge\MonologCollector;
|
|
use Illuminate\Database\QueryException;
|
|
use Monolog\Logger;
|
|
|
|
class CurrentTemplate
|
|
{
|
|
protected static $template;
|
|
protected static $initialized = false;
|
|
|
|
/**
|
|
* Getter for currently set template
|
|
* @return Module
|
|
* @throws \ErrorException
|
|
*/
|
|
public static function get()
|
|
{
|
|
if (!self::$initialized) {
|
|
try {
|
|
self::$template = Module::where('is_template', true)
|
|
->where('enabled', true)
|
|
->first();
|
|
} catch (QueryException $e) {
|
|
throw new \ErrorException('DB not migrated, please, do so!');
|
|
}
|
|
if (self::$template) {
|
|
self::$template->module_settings = json_decode(self::$template->module_settings);
|
|
}
|
|
|
|
self::$initialized = true;
|
|
}
|
|
|
|
return self::$template;
|
|
}
|
|
|
|
/**
|
|
* Shortcut for getting template handler
|
|
*
|
|
* @return string
|
|
* @throws \ErrorException
|
|
*/
|
|
public static function handler()
|
|
{
|
|
$template = self::get();
|
|
|
|
if (!$template) {
|
|
throw new \ErrorException('No template selected, no handler available!');
|
|
}
|
|
|
|
return $template->handler;
|
|
}
|
|
|
|
/**
|
|
* Reset currently set template and load another one on next call of get() method.
|
|
*/
|
|
public static function reset()
|
|
{
|
|
self::$initialized = false;
|
|
}
|
|
} |