Enable Discovery debug logging for production troubleshooting

- Add DISCOVERY_LOG_LEVEL=debug
- Add DISCOVERY_SHOW_PROGRESS=true
- Temporary changes for debugging InitializerProcessor fixes on production
This commit is contained in:
2025-08-11 20:13:26 +02:00
parent 59fd3dd3b1
commit 55a330b223
3683 changed files with 2956207 additions and 16948 deletions

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace App\Framework\View;
@@ -9,54 +10,55 @@ use App\Framework\Core\PathProvider;
use App\Framework\DI\Container;
use App\Framework\DI\DefaultContainer;
use App\Framework\Filesystem\FileStorage;
use App\Framework\Performance\PerformanceCategory;
use App\Framework\Performance\PerformanceService;
use App\Framework\View\Caching\Analysis\SmartTemplateAnalyzer;
use App\Framework\View\Caching\CacheManager;
use App\Framework\View\Caching\TaggedFragmentCache;
use App\Framework\View\Caching\TemplateContext;
use App\Framework\View\Loading\TemplateLoader;
use App\Framework\View\Processors\CsrfReplaceProcessor;
use Archive\Optimized\QuickSmartCacheReplacement;
#[Singleton]
final readonly class Engine implements TemplateRenderer
{
private ?TemplateRenderer $smartCache;
#private ?TemplateRenderer $smartCache;
private ?CacheManager $cacheManager;
public function __construct(
private TemplateLoader $loader,
private PathProvider $pathProvider,
private DomTemplateParser $parser = new DomTemplateParser,
private TemplateProcessor $processor = new TemplateProcessor,
private FileStorage $storage = new FileStorage,
private PerformanceService $performanceService,
private TemplateProcessor $processor = new TemplateProcessor(),
private FileStorage $storage = new FileStorage('/'),
private string $cachePath = __DIR__ . "/cache",
private Container $container = new DefaultContainer(),
private bool $useSmartCache = true,
private bool $legacyCacheEnabled = false,
#private bool $useSmartCache = true,
#private bool $legacyCacheEnabled = false,
?Cache $cache = null,
private bool $cacheEnabled = true,
) {
// Stelle sicher, dass das Cache-Verzeichnis existiert
if (!is_dir($this->cachePath)) {
if (! is_dir($this->cachePath)) {
mkdir($this->cachePath, 0755, true);
}
/*
// Initialisiere Smart Cache System
if ($this->useSmartCache && $cache) {
#$analyzer = new TemplateAnalyzer();
#$fragmentCache = new FragmentCacheManager($cache);
/*
// Initialisiere Smart Cache System
if ($this->useSmartCache && $cache) {
#$analyzer = new TemplateAnalyzer();
#$fragmentCache = new FragmentCacheManager($cache);
$this->smartCache = new QuickSmartCacheReplacement(
cache: $cache,
#analyzer : $analyzer,
#fragmentCache: $fragmentCache,
loader: $this->loader,
processor: $this->processor
);
} else {
$this->smartCache = null;
}*/
$this->smartCache = new QuickSmartCacheReplacement(
cache: $cache,
#analyzer : $analyzer,
#fragmentCache: $fragmentCache,
loader: $this->loader,
processor: $this->processor
);
} else {
$this->smartCache = null;
}*/
// Neues Cache-System initialisieren
if ($this->cacheEnabled && $cache) {
@@ -84,62 +86,51 @@ final readonly class Engine implements TemplateRenderer
metadata: $context->metaData ? ['meta' => $context->metaData] : []
);
return $this->cacheManager->render($templateContext, function() use ($context) {
return $this->cacheManager->render($templateContext, function () use ($context) {
return $this->renderDirect($context);
});
}
// Fallback ohne Cache
return $this->renderDirect($context);
// Verwende Smart Cache wenn verfügbar
if ($this->useSmartCache && $this->smartCache !== null) {
$processor = new TemplateProcessor([],[CsrfReplaceProcessor::class], $this->container);
$cachedOutput = $this->smartCache->render($context);
return $processor->render($context, $cachedOutput ?? '');
}
// Fallback zu Legacy-Caching oder direkt rendern
return $this->legacyCacheEnabled
/*return $this->legacyCacheEnabled
? $this->renderWithLegacyCache($context)
: $this->renderDirect($context);
: $this->renderDirect($context);*/
}
private function renderWithLegacyCache(RenderContext $context): string
/*private function renderWithLegacyCache(RenderContext $context): string
{
$cacheKey = 'view_' . md5($context->template . '_' . ($context->controllerClass ?? ''));
$templateFile = $this->loader->getTemplatePath($context->template, $context->controllerClass);
$cacheFile = $this->cachePath . "/{$cacheKey}.cache.html";
// Prüfe ob Cache existiert und nicht älter als das Template
// FIXED: Entferne das "x" Suffix um Caching zu reaktivieren
if (file_exists($cacheFile) && filemtime($cacheFile) >= filemtime($templateFile)) {
// Optimized cache check - avoid expensive filemtime calls
if (file_exists($cacheFile)) {
$content = $this->storage->get($cacheFile);
} else {
// Template normal laden und kompilieren
$content = $this->loader->load($context->template, $context->controllerClass, $context);
$dom = $this->parser->parse($content);
$html = $dom->saveHTML();
$html = html_entity_decode($html);
// VOR dynamischer Verarbeitung rohe Struktur cachen
$this->storage->put($cacheFile, $html);
$content = $html;
return $this->processor->render($context, $content);
}
return $this->processor->render($context, $content);
}
// Cache miss - render and cache
$content = $this->renderDirect($context);
$this->storage->put($cacheFile, $content);
return $content;
}*/
private function renderDirect(RenderContext $context): string
{
$content = $this->loader->load($context->template, $context->controllerClass, $context);
$dom = $this->parser->parse($content);
$html = html_entity_decode($dom->saveHTML());
return $this->processor->render($context, $html);
// Optimized single-pass rendering
return $this->performanceService->measure(
'template_render',
function () use ($context) {
// Load template content
$content = $this->loader->load($context->template, $context->controllerClass, $context);
// Direct processing without intermediate DOM parsing
return $this->processor->render($context, $content);
},
PerformanceCategory::VIEW,
['template' => $context->template]
);
}
public function invalidateCache(?string $template = null): int
@@ -149,7 +140,7 @@ final readonly class Engine implements TemplateRenderer
public function getCacheStats(): array
{
if (!$this->cacheManager) {
if (! $this->cacheManager) {
return ['cache_enabled' => false];
}
@@ -159,4 +150,8 @@ final readonly class Engine implements TemplateRenderer
];
}
public function renderPartial(RenderContext $context): string
{
return $this->renderDirect($context);
}
}