- Move 12 markdown files from root to docs/ subdirectories - Organize documentation by category: • docs/troubleshooting/ (1 file) - Technical troubleshooting guides • docs/deployment/ (4 files) - Deployment and security documentation • docs/guides/ (3 files) - Feature-specific guides • docs/planning/ (4 files) - Planning and improvement proposals Root directory cleanup: - Reduced from 16 to 4 markdown files in root - Only essential project files remain: • CLAUDE.md (AI instructions) • README.md (Main project readme) • CLEANUP_PLAN.md (Current cleanup plan) • SRC_STRUCTURE_IMPROVEMENTS.md (Structure improvements) This improves: ✅ Documentation discoverability ✅ Logical organization by purpose ✅ Clean root directory ✅ Better maintainability
81 lines
2.7 KiB
PHP
81 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\View\Processors;
|
|
|
|
use App\Framework\Core\PathProvider;
|
|
use App\Framework\Template\Processing\DomProcessor;
|
|
use App\Framework\View\DomHeadService;
|
|
use App\Framework\View\DomWrapper;
|
|
use App\Framework\View\Exceptions\TemplateProcessorException;
|
|
use App\Framework\View\RenderContext;
|
|
|
|
final class AssetInjector implements DomProcessor
|
|
{
|
|
private array $manifest;
|
|
|
|
public function __construct(
|
|
PathProvider $pathProvider,
|
|
private DomHeadService $headService,
|
|
string $manifestPath = '',
|
|
) {
|
|
|
|
$manifestPath = $pathProvider->resolvePath('/public/.vite/manifest.json');
|
|
;
|
|
|
|
#$manifestPath = dirname(__DIR__, 3) . '../public/.vite/manifest.json';
|
|
|
|
if (! is_file($manifestPath)) {
|
|
throw TemplateProcessorException::manifestNotFound($manifestPath);
|
|
}
|
|
$json = file_get_contents($manifestPath);
|
|
|
|
$this->manifest = json_decode($json, true) ?? [];
|
|
}
|
|
|
|
public function process(DomWrapper $dom, RenderContext $context): DomWrapper
|
|
{
|
|
// Skip if this is a partial render (e.g. component)
|
|
if ($context->isPartial ?? false) {
|
|
return $dom;
|
|
}
|
|
|
|
// JS-Key, wie im Manifest unter "resources/js/main.js"
|
|
$jsKey = 'resources/js/main.js';
|
|
|
|
// Debug: Log what we have in manifest
|
|
error_log("AssetInjector: Processing with manifest: " . json_encode($this->manifest));
|
|
|
|
// Check if we have the JS key in manifest
|
|
if (! isset($this->manifest[$jsKey])) {
|
|
error_log("AssetInjector: Key '$jsKey' not found in manifest!");
|
|
|
|
return $dom;
|
|
}
|
|
|
|
// Debug: Log the CSS array
|
|
if (isset($this->manifest[$jsKey]['css'])) {
|
|
error_log("AssetInjector: CSS array found: " . json_encode($this->manifest[$jsKey]['css']));
|
|
} else {
|
|
error_log("AssetInjector: No CSS array in manifest entry!");
|
|
}
|
|
|
|
// Use DomHeadService instead of direct manipulation
|
|
if (! empty($this->manifest[$jsKey]['css']) && is_array($this->manifest[$jsKey]['css'])) {
|
|
foreach ($this->manifest[$jsKey]['css'] as $cssFile) {
|
|
error_log("AssetInjector: Adding CSS file: " . $cssFile);
|
|
$this->headService->addStylesheet($dom, '/' . ltrim($cssFile, '/'));
|
|
}
|
|
}
|
|
|
|
// --- JS Main Script ---
|
|
if (isset($this->manifest[$jsKey]['file']) && str_ends_with($this->manifest[$jsKey]['file'], '.js')) {
|
|
error_log("AssetInjector: Adding JS file: " . $this->manifest[$jsKey]['file']);
|
|
$this->headService->addScript($dom, '/' . ltrim($this->manifest[$jsKey]['file'], '/'));
|
|
}
|
|
|
|
return $dom;
|
|
}
|
|
}
|