'text/javascript', 'mjs' => 'text/javascript', 'css' => 'text/css', 'map' => 'application/json', 'json' => 'application/json', 'svg' => 'image/svg+xml', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'webp' => 'image/webp', 'gif' => 'image/gif', 'woff2' => 'font/woff2', ]; /** @var array, css: list}>|null */ private ?array $cache = null; public function __construct(private readonly PluginManager $plugins) {} /** * Für das Frontend (window.__inhausPlugins): aktive Plugins mit Oberfläche. * * @return array, css: list}> */ public function forFrontend(): array { if ($this->cache !== null) { return $this->cache; } $this->cache = []; foreach ($this->plugins->loaded() as $slug => $plugin) { $manifest = $plugin->manifest; if ($manifest->core || ! is_file($manifest->path.'/'.self::MANIFEST)) { continue; } $data = json_decode((string) file_get_contents($manifest->path.'/'.self::MANIFEST), true); if (! is_array($data)) { continue; } $clean = fn ($file) => is_string($file) && preg_match('#^[A-Za-z0-9_./-]+$#', $file) && ! str_contains($file, '..') ? $file : null; $this->cache[$slug] = [ 'base' => '/plugin-assets/'.rawurlencode($slug).'/'.rawurlencode($manifest->version).'/', 'components' => array_filter(array_map($clean, (array) ($data['components'] ?? [])), fn ($file, $key) => $file !== null && preg_match('#^[A-Za-z0-9_/-]+$#', (string) $key), ARRAY_FILTER_USE_BOTH), 'css' => array_values(array_filter(array_map($clean, (array) ($data['css'] ?? [])))), ]; } return $this->cache; } /** * Import Map für Plugins: dieselben Module wie im Portal. * * @return array{imports: array} */ public static function importMap(): array { $v = '?v='.Version::VERSION; return ['imports' => [ 'vue' => '/sdk/vue.js'.$v, '@inertiajs/vue3' => '/sdk/inertia.js'.$v, '@inhaus/ui' => '/sdk/ui.js'.$v, ]]; } /** * Pfad einer ausgelieferten Datei – nur aus dist/ eines aktiven Kunden-Plugins. */ public function file(string $slug, string $path): ?string { $plugin = $this->plugins->loaded()[$slug] ?? null; $extension = strtolower(pathinfo($path, PATHINFO_EXTENSION)); if (! $plugin || $plugin->manifest->core || ! isset(self::TYPES[$extension]) || str_contains($path, '..')) { return null; } $dist = realpath($plugin->manifest->path.'/dist'); $file = realpath($plugin->manifest->path.'/dist/'.$path); return $dist && $file && str_starts_with($file, $dist.DIRECTORY_SEPARATOR) && is_file($file) ? $file : null; } }