<?php
namespace Engine\Theme\JSLoader; abstract class LoaderAbstract { protected array $filesList = []; protected array $filesParams = []; protected array $sentFilesList = []; protected array $loadedGroups = []; protected array $options = []; public function __construct() { } abstract public function initialize(): void; public function setOption(string $key, mixed $value): void { $this->options[$key] = $value; } public function getOption(string $key): mixed { return $this->options[$key] ?? null; } abstract public function preload(): ?string; abstract public function postload(): ?string; abstract public function load(string $file, array $params = []): ?string; abstract public function render(?string $renderId = null, array $params = []): ?string; public function loadGroup(string $groupName, array $params = []): void { $resourceLoaderCfg = \Theme::getInstance()->getResourceLoaderCfg(); if (!$resourceLoaderCfg) { throw new \Exception("ResourceLoader configs not loaded. Please check this out"); } if (!isset($resourceLoaderCfg['groups'][$groupName])) { throw new \Exception("Cannot load group '{$groupName}'"); } $params['group'] = $groupName; if (!empty($resourceLoaderCfg['groups'][$groupName]['js'])) { if (isset($params['priority'])) { $groupPriority = (int)$params['priority']; } else { $groupPriority = (int)(PHP_INT_MAX / 2) + count($this->loadedGroups) * 2500; } foreach ($resourceLoaderCfg['groups'][$groupName]['js'] as $file) { $params['priority'] = $groupPriority + count($this->filesList); $this->load($file, $params); } } $this->loadedGroups[$groupName] = $groupName; } } 