singleton(\App\Framework\Logging\Logger::class, $logger); $container->singleton(\App\Framework\Performance\MemoryMonitor::class, $memoryMonitor); $container->singleton(\App\Framework\Reflection\ReflectionProvider::class, $reflectionProvider); $container->singleton(\App\Framework\Filesystem\FileSystemService::class, $fileSystemService); echo "โœ… Dependencies initialized\n"; // Create factory $factory = new DiscoveryServiceFactory($container, $pathProvider, $cache, $clock); echo "โœ… Factory created\n"; // Test 1: Create service for testing environment echo "\n๐Ÿงช Test 1: Testing Environment Configuration\n"; $testingService = $factory->createForTesting([ $pathProvider->getBasePath() . '/src/Application/Admin', ]); echo "โœ… Testing service created successfully\n"; // Test 2: Create service for development environment echo "\n๐Ÿงช Test 2: Development Environment Configuration\n"; $devService = $factory->createForDevelopment([ $pathProvider->getBasePath() . '/src/Application/Admin', ]); echo "โœ… Development service created successfully\n"; // Test 3: Create service with custom configuration echo "\n๐Ÿงช Test 3: Custom Configuration\n"; $customConfig = new DiscoveryConfiguration( paths: [$pathProvider->getBasePath() . '/src/Application/Admin'], useCache: false, enablePerformanceTracking: true, enableMemoryMonitoring: true, maxFilesPerBatch: 25 ); $customService = $factory->create($customConfig); echo "โœ… Custom service created successfully\n"; // Test 4: Validate dependencies echo "\n๐Ÿงช Test 4: Dependency Validation\n"; $issues = $factory->validateDependencies($customConfig); if (empty($issues)) { echo "โœ… All dependencies validated successfully\n"; } else { echo "โš ๏ธ Dependency issues found:\n"; foreach ($issues as $issue) { echo " - $issue\n"; } } // Test 5: Run a quick discovery echo "\n๐Ÿงช Test 5: Quick Discovery Run\n"; $startTime = microtime(true); $startMemory = memory_get_usage(true); $options = new DiscoveryOptions( scanType: ScanType::FULL, paths: [$pathProvider->getBasePath() . '/src/Application/Admin'], useCache: false ); $registry = $testingService->discoverWithOptions($options); $endTime = microtime(true); $endMemory = memory_get_usage(true); echo "โœ… Discovery completed successfully!\n"; // Results echo "\n๐Ÿ“Š Results:\n"; echo " Total items: " . count($registry) . "\n"; echo " Attributes: " . count($registry->attributes) . "\n"; echo " Routes: " . count($registry->routes) . "\n"; echo " Templates: " . count($registry->templates) . "\n"; echo " Interfaces: " . count($registry->interfaces) . "\n"; // Performance echo "\nโšก Performance:\n"; echo " Duration: " . round(($endTime - $startTime) * 1000, 2) . "ms\n"; echo " Memory used: " . round(($endMemory - $startMemory) / 1024 / 1024, 2) . "MB\n"; echo " Peak memory: " . round(memory_get_peak_usage(true) / 1024 / 1024, 2) . "MB\n"; // Show some sample routes $routes = $registry->routes->getAll(); if (! empty($routes)) { echo "\n๐Ÿ›ฃ๏ธ Sample Routes Found:\n"; foreach (array_slice($routes, 0, 5) as $route) { echo " - {$route->method->value} {$route->path} -> {$route->class->getShortName()}::{$route->handler->toString()}\n"; } } echo "\n๐ŸŽ‰ All tests passed successfully!\n"; echo "\n๐Ÿ† Key Benefits of New DI System:\n"; echo " โœ… Simplified constructor (11 โ†’ 6 parameters)\n"; echo " โœ… Configuration-driven setup\n"; echo " โœ… Environment-aware defaults\n"; echo " โœ… Factory pattern for easy creation\n"; echo " โœ… Dependency validation\n"; echo " โœ… Better testability\n"; echo " โœ… Improved maintainability\n"; } catch (Throwable $e) { echo "\nโŒ Error during testing:\n"; echo " Message: " . $e->getMessage() . "\n"; echo " File: " . $e->getFile() . ":" . $e->getLine() . "\n"; echo " Stack trace:\n" . $e->getTraceAsString() . "\n"; exit(1); }