- Fix RedisCache driver to handle MGET failures gracefully with fallback - Add comprehensive discovery context comparison debug tools - Identify root cause: WEB context discovery missing 166 items vs CLI - WEB context missing RequestFactory class entirely (52 vs 69 commands) - Improved exception handling with detailed binding diagnostics
109 lines
4.2 KiB
PHP
109 lines
4.2 KiB
PHP
<?php
|
|
|
|
require __DIR__ . '/vendor/autoload.php';
|
|
|
|
use App\Framework\Performance\EnhancedPerformanceCollector;
|
|
use App\Framework\DateTime\SystemClock;
|
|
use App\Framework\DateTime\SystemHighResolutionClock;
|
|
use App\Framework\Core\AppBootstrapper;
|
|
use App\Framework\Performance\MemoryMonitor;
|
|
use App\Framework\Context\ExecutionContext;
|
|
|
|
echo "=== Discovery Context Compare ===\n";
|
|
|
|
function testDiscoveryInContext($contextName, $setupServer = null) {
|
|
// Clear any previous $_SERVER state
|
|
foreach (array_keys($_SERVER) as $key) {
|
|
if (str_starts_with($key, 'HTTP_') || str_starts_with($key, 'SERVER_')) {
|
|
unset($_SERVER[$key]);
|
|
}
|
|
}
|
|
|
|
// Set up context
|
|
if ($setupServer) {
|
|
$setupServer();
|
|
}
|
|
|
|
$basePath = __DIR__;
|
|
$clock = new SystemClock();
|
|
$highResClock = new SystemHighResolutionClock();
|
|
$memoryMonitor = new MemoryMonitor();
|
|
$collector = new EnhancedPerformanceCollector($clock, $highResClock, $memoryMonitor, enabled: false);
|
|
$bootstrapper = new AppBootstrapper($basePath, $collector, $memoryMonitor);
|
|
|
|
try {
|
|
$container = $bootstrapper->bootstrapWorker();
|
|
$registry = $container->get('App\\Framework\\Discovery\\Results\\DiscoveryRegistry');
|
|
|
|
// Get initializers
|
|
$initializerResults = $registry->attributes->get(\App\Framework\DI\Initializer::class);
|
|
|
|
$requestFactoryFound = false;
|
|
$requestFactoryMethods = [];
|
|
$totalInitializers = count($initializerResults);
|
|
|
|
foreach ($initializerResults as $discoveredAttribute) {
|
|
if (str_contains($discoveredAttribute->className, 'RequestFactory')) {
|
|
$requestFactoryFound = true;
|
|
$requestFactoryMethods[] = $discoveredAttribute->methodName;
|
|
}
|
|
}
|
|
|
|
echo "Context: $contextName\n";
|
|
echo " Detected as: " . ExecutionContext::detect()->getType()->value . "\n";
|
|
echo " Total items: " . count($registry) . "\n";
|
|
echo " Total initializers: " . $totalInitializers . "\n";
|
|
echo " RequestFactory found: " . ($requestFactoryFound ? "YES" : "NO") . "\n";
|
|
if ($requestFactoryFound) {
|
|
echo " RequestFactory methods: " . implode(", ", $requestFactoryMethods) . "\n";
|
|
}
|
|
|
|
// Test actual Request resolution
|
|
try {
|
|
$request = $container->get('App\\Framework\\Http\\Request');
|
|
echo " Request resolution: SUCCESS (" . get_class($request) . ")\n";
|
|
} catch (Throwable $e) {
|
|
echo " Request resolution: FAILED (" . $e->getMessage() . ")\n";
|
|
}
|
|
|
|
echo "\n";
|
|
|
|
return [
|
|
'context' => ExecutionContext::detect()->getType()->value,
|
|
'total_items' => count($registry),
|
|
'total_initializers' => $totalInitializers,
|
|
'request_factory_found' => $requestFactoryFound,
|
|
'request_resolution' => isset($request)
|
|
];
|
|
|
|
} catch (Throwable $e) {
|
|
echo "Context: $contextName - ERROR: " . $e->getMessage() . "\n\n";
|
|
return null;
|
|
}
|
|
}
|
|
|
|
// Test CLI context
|
|
$cliResult = testDiscoveryInContext('CLI (clean)', function() {
|
|
// Ensure clean CLI context
|
|
});
|
|
|
|
// Test WEB context
|
|
$webResult = testDiscoveryInContext('WEB (simulated)', function() {
|
|
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (compatible)';
|
|
$_SERVER['SERVER_NAME'] = 'localhost';
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
$_SERVER['REQUEST_URI'] = '/';
|
|
$_SERVER['HTTPS'] = 'on';
|
|
});
|
|
|
|
// Compare results
|
|
if ($cliResult && $webResult) {
|
|
echo "=== COMPARISON ===\n";
|
|
echo "CLI total items: {$cliResult['total_items']}\n";
|
|
echo "WEB total items: {$webResult['total_items']}\n";
|
|
echo "Difference: " . ($cliResult['total_items'] - $webResult['total_items']) . " items\n";
|
|
echo "RequestFactory - CLI: " . ($cliResult['request_factory_found'] ? "FOUND" : "MISSING") . "\n";
|
|
echo "RequestFactory - WEB: " . ($webResult['request_factory_found'] ? "FOUND" : "MISSING") . "\n";
|
|
echo "Request resolution - CLI: " . ($cliResult['request_resolution'] ? "SUCCESS" : "FAILED") . "\n";
|
|
echo "Request resolution - WEB: " . ($webResult['request_resolution'] ? "SUCCESS" : "FAILED") . "\n";
|
|
} |