|
@@ -2,6 +2,8 @@
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
+use Illuminate\Support\Facades\Cache;
|
|
|
+use App\Http\Controllers\ProductController;
|
|
|
use App\Services\LiquidTags\LiquidTagProduct;
|
|
|
use App\Services\LiquidTags\LiquidTagVideo;
|
|
|
use App\Services\LiquidTags\LiquidTagBanner;
|
|
@@ -22,12 +24,60 @@ class LiquidRenderer
|
|
|
protected static ?string $baseTemplatePath = null;
|
|
|
|
|
|
|
|
|
- public static function render(string $templateName, array $data = []): string
|
|
|
+ public static function render(string $templateName, array $data = [],?string $cacheKey = null): string
|
|
|
{
|
|
|
|
|
|
self::initializeLiquidSettings();
|
|
|
self::initializeBaseTemplatePath();
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ if ($cacheKey) {
|
|
|
+ $cacheDuration = config('liquid.cache_duration', 300);
|
|
|
+
|
|
|
+
|
|
|
+ $domain=app('dist')->domain;
|
|
|
+ if(!$domain)
|
|
|
+ {
|
|
|
+ abort('403');
|
|
|
+ }
|
|
|
+ return Cache::tags([$domain, 'dist'])->remember("liquid_{$cacheKey}", $cacheDuration, function () use ($templateName, $data) {
|
|
|
+ return self::processTemplate($templateName, $data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return self::processTemplate($templateName, $data);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private static function processTemplate(string $templateName, array $data): string
|
|
|
+ {
|
|
|
$template = self::createTemplateInstance();
|
|
|
|
|
|
$template->registerTag('page', LiquidTagPage::class);
|
|
@@ -38,22 +88,20 @@ class LiquidRenderer
|
|
|
$template->registerTag('contactus', LiquidTagContactUs::class);
|
|
|
$template->registerFilter(Filters::class);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
$config = self::getGlobalConfig();
|
|
|
$data['site'] = array_merge($data['site'] ?? [], $config);
|
|
|
|
|
|
-
|
|
|
try {
|
|
|
$parsedTemplate = $template->parseFile($templateName);
|
|
|
} catch (\Exception $e) {
|
|
|
throw new \RuntimeException("Template not found: {$templateName}", 0, $e);
|
|
|
}
|
|
|
|
|
|
- return $parsedTemplate->render($data);
|
|
|
+ $now_string=date('Y-m-d H:i:s');
|
|
|
+ return $parsedTemplate->render($data);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
private static function initializeBaseTemplatePath(): void
|
|
|
{
|
|
@@ -77,7 +125,11 @@ class LiquidRenderer
|
|
|
private static function createTemplateInstance(): Template
|
|
|
{
|
|
|
$template = new Template(self::$baseTemplatePath);
|
|
|
-
|
|
|
+
|
|
|
+ $enableCache = config('liquid.cache_enabled', false);
|
|
|
+ if ($enableCache) {
|
|
|
+ $template->setCache(new FileCache(['cache_dir' => storage_path('framework/cache/data')]));
|
|
|
+ }
|
|
|
return $template;
|
|
|
}
|
|
|
|