<?php
namespace Engine\Theme\JSLoader\Export; abstract class AbstractExport { protected array $data = []; public function __construct() { } abstract public function gather(): static; abstract public function asJSON(): string; public function rehashOutputFilename(array $hash): array { return $hash; } protected function exportBulkVariables(string $jsVar, array $variables, string $pre = ""): string { return sprintf("{$pre}{$jsVar} = %s;", json_encode($variables)); } protected function exportIndividualVariables(string $jsVar, array $variables, string $pre = ""): string { $output = []; foreach ($variables as $jsKey => $values) { if (is_array($values)) { $output[] = $this->exportIndividualVariables("['{$jsKey}']", $values, $pre . $jsVar); } else { $output[] = sprintf("{$pre}{$jsVar}['{$jsKey}'] = %s;", json_encode($values)); } } return implode("\n", $output); } protected function exportBulkVariablesAndMerge(string $jsVar, array $variables, string $pre = ""): string { return sprintf("{$pre}%s = Object.assign({$pre}%s || {}, %s);", $jsVar, $jsVar, json_encode($variables)); } } 