Files
michaelschiemer/tests/debug/test-initializer-discovery-details.php
Michael Schiemer 55a330b223 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
2025-08-11 20:13:26 +02:00

118 lines
4.3 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use App\Framework\Cache\Driver\InMemoryCache;
use App\Framework\Cache\GeneralCache;
use App\Framework\Core\PathProvider;
use App\Framework\DateTime\SystemClock;
use App\Framework\DI\DefaultContainer;
use App\Framework\DI\Initializer;
use App\Framework\Discovery\Factory\DiscoveryServiceFactory;
use App\Framework\Serializer\Json\JsonSerializer;
echo "=== Debugging Initializer Discovery Details ===\n\n";
try {
$projectRoot = dirname(__DIR__, 2);
$srcPath = $projectRoot . '/src';
$container = new DefaultContainer();
$pathProvider = new PathProvider($projectRoot);
$clock = new SystemClock();
$cacheDriver = new InMemoryCache();
$serializer = new JsonSerializer();
$cache = new GeneralCache($cacheDriver, $serializer);
$factory = new DiscoveryServiceFactory($container, $pathProvider, $cache, $clock);
$discoveryService = $factory->createForDevelopment([$srcPath]);
echo "Running discovery...\n";
$registry = $discoveryService->discover();
echo "Total items discovered: " . count($registry) . "\n";
echo "Total Initializers found: " . $registry->attributes->getCount(Initializer::class) . "\n\n";
// Get all initializers
$initializers = $registry->attributes->get(Initializer::class);
echo "=== Analyzing Each Initializer ===\n";
$counter = 0;
foreach ($initializers as $mapping) {
$counter++;
$className = $mapping->class->getFullyQualified();
$methodName = $mapping->method ? $mapping->method->toString() : '(class)';
echo "\n[$counter] $className::$methodName\n";
// Check mapped data
if ($mapping->mappedData) {
echo " Mapped Data:\n";
foreach ($mapping->mappedData as $key => $value) {
if ($key === 'contexts') {
if ($value === null) {
echo " - contexts: NULL ⚠️ (will be skipped!)\n";
} elseif (is_array($value)) {
echo " - contexts: [" . implode(', ', array_map(fn ($c) => $c?->value ?? 'null', $value)) . "]\n";
} else {
echo " - contexts: " . json_encode($value) . "\n";
}
} else {
echo " - $key: " . (is_string($value) ? $value : json_encode($value)) . "\n";
}
}
} else {
echo " ❌ No mapped data!\n";
}
// Check attributes
if ($mapping->attributes) {
echo " Raw Attributes:\n";
foreach ($mapping->attributes as $attr) {
if ($attr instanceof Initializer) {
$reflection = new ReflectionObject($attr);
$props = $reflection->getProperties();
foreach ($props as $prop) {
$prop->setAccessible(true);
$val = $prop->getValue($attr);
if ($prop->getName() === 'contexts') {
if ($val === null) {
echo " - contexts (raw): NULL\n";
} elseif (is_array($val)) {
echo " - contexts (raw): [" . implode(', ', array_map(fn ($c) => $c?->value ?? 'null', $val)) . "]\n";
} else {
echo " - contexts (raw): " . json_encode($val) . "\n";
}
}
}
}
}
}
}
echo "\n=== Summary ===\n";
echo "Total Initializers analyzed: $counter\n";
// Count how many have null contexts
$nullContexts = 0;
$withContexts = 0;
foreach ($initializers as $mapping) {
if ($mapping->mappedData && isset($mapping->mappedData['contexts'])) {
if ($mapping->mappedData['contexts'] === null) {
$nullContexts++;
} else {
$withContexts++;
}
}
}
echo "Initializers with NULL contexts: $nullContexts (will be skipped)\n";
echo "Initializers with valid contexts: $withContexts\n";
} catch (Exception $e) {
echo "❌ Error: " . $e->getMessage() . "\n";
echo "Stack trace:\n" . $e->getTraceAsString() . "\n";
}