getBasePath() . '/src/Application/Admin'; echo "Testing directory: $adminDir\n"; if (is_dir($adminDir)) { $phpFiles = glob($adminDir . '/*.php'); echo "PHP files found: " . count($phpFiles) . "\n"; if (count($phpFiles) > 0) { echo "First few files:\n"; foreach (array_slice($phpFiles, 0, 3) as $file) { echo " - " . basename($file) . "\n"; } } } else { echo "Directory not found!\n"; } echo "āœ… Discovery service created with new architecture\n"; // Quick manual test of class extraction echo "\nšŸ” Manual class extraction test:\n"; $testFile = $adminDir . '/Dashboard.php'; if (file_exists($testFile)) { echo "Testing class extraction on: " . basename($testFile) . "\n"; // Create a file object $fileInfo = new \SplFileInfo($testFile); $file = \App\Framework\Filesystem\File::fromSplFileInfo($fileInfo); // Test class extraction $extractor = new \App\Framework\Discovery\Processing\ClassExtractor($fileSystemService); $classNames = $extractor->extractFromFile($file); echo "Classes found: " . count($classNames) . "\n"; foreach ($classNames as $className) { echo " - " . $className->getFullyQualified() . "\n"; } // Debug: Let's read the file content directly and check patterns echo "\nšŸ” Debug file content:\n"; $content = $fileSystemService->readFile($file); echo "File size: " . strlen($content) . " characters\n"; // Test if content has class keyword if (str_contains($content, 'class ')) { echo "āœ… Contains 'class ' keyword\n"; } else { echo "āŒ Does NOT contain 'class ' keyword\n"; } // Test namespace extraction if (preg_match('/^\s*namespace\s+([^;]+);/m', $content, $matches)) { echo "āœ… Namespace found: " . $matches[1] . "\n"; } else { echo "āŒ No namespace found\n"; } // Test class extraction pattern $pattern = '/^\s*(?:final\s+)?(?:abstract\s+)?(?:readonly\s+)?class\s+([a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/mi'; if (preg_match_all($pattern, $content, $matches)) { echo "āœ… Class pattern matched: " . count($matches[1]) . " classes\n"; foreach ($matches[1] as $className) { echo " - Class: $className\n"; } } else { echo "āŒ Class pattern did not match\n"; } // Test reflection on the class directly echo "\nšŸ” Manual reflection test on Dashboard class:\n"; try { $dashboardClass = \App\Application\Admin\Dashboard::class; $reflection = new \ReflectionClass($dashboardClass); echo "āœ… Reflection created for: $dashboardClass\n"; $methods = $reflection->getMethods(); echo "Methods found: " . count($methods) . "\n"; foreach ($methods as $method) { $attributes = $method->getAttributes(); if (! empty($attributes)) { echo " Method {$method->getName()} has " . count($attributes) . " attributes:\n"; foreach ($attributes as $attr) { echo " - " . $attr->getName() . "\n"; if (str_contains($attr->getName(), 'Route')) { echo " āœ… ROUTE ATTRIBUTE FOUND!\n"; try { $instance = $attr->newInstance(); echo " - Instance created successfully\n"; if (method_exists($instance, 'path')) { echo " - Path: " . $instance->path . "\n"; } if (method_exists($instance, 'method')) { echo " - Method: " . $instance->method->value . "\n"; } } catch (\Throwable $e) { echo " - Failed to create instance: " . $e->getMessage() . "\n"; } } } } } } catch (\Throwable $e) { echo "āŒ Reflection failed: " . $e->getMessage() . "\n"; } } // Test health status echo "\nšŸ“Š Health Status:\n"; $health = $discoveryService->getHealthStatus(); foreach ($health as $key => $value) { if (is_array($value)) { echo " $key:\n"; foreach ($value as $subKey => $subValue) { echo " $subKey: " . (is_array($subValue) ? json_encode($subValue) : $subValue) . "\n"; } } else { echo " $key: $value\n"; } } // Test discovery with limited scope for faster testing echo "\nšŸ” Running Discovery (limited scope)...\n"; $startTime = microtime(true); $startMemory = memory_get_usage(true); $options = new DiscoveryOptions( scanType: ScanType::FULL, paths: [ $pathProvider->getBasePath() . '/src/Application/Admin', ], useCache: false ); $registry = $discoveryService->discoverWithOptions($options); $endTime = microtime(true); $endMemory = memory_get_usage(true); echo "āœ… Discovery completed!\n"; echo "\nšŸ“ˆ Results:\n"; echo " Total items: " . count($registry) . "\n"; echo " Attributes: " . count($registry->attributes) . "\n"; echo " Interfaces: " . count($registry->interfaces) . "\n"; echo " Routes: " . count($registry->routes) . "\n"; echo " Templates: " . count($registry->templates) . "\n"; 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"; // Test registry statistics echo "\nšŸ“Š Memory Statistics:\n"; $stats = $registry->getMemoryStats(); foreach ($stats as $type => $stat) { if (is_array($stat)) { echo " $type:\n"; foreach ($stat as $key => $value) { echo " $key: $value\n"; } } else { echo " $type: $stat\n"; } } // Show some example discovered items echo "\nšŸ” Sample Discoveries:\n"; // Show attributes $attributeTypes = $registry->attributes->getAllTypes(); if (! empty($attributeTypes)) { echo " Attribute Types Found:\n"; foreach (array_slice($attributeTypes, 0, 5) as $type) { $count = count($registry->attributes->get($type)); echo " - $type ($count instances)\n"; } // Debug: Look for Route attributes specifically echo "\n šŸ” Debug - Looking for Route attributes:\n"; foreach ($attributeTypes as $type) { if (str_contains($type, 'Route')) { echo " āœ… Route attribute found: $type\n"; $instances = $registry->attributes->get($type); foreach ($instances as $instance) { echo " - Method: " . ($instance->method ? $instance->method->toString() : 'class-level') . "\n"; } } } if (! array_filter($attributeTypes, fn ($type) => str_contains($type, 'Route'))) { echo " āŒ No Route attributes found. Looking for all attribute types:\n"; foreach ($attributeTypes as $type) { echo " - $type\n"; } } } // Show routes $routes = $registry->routes->getAll(); if (! empty($routes)) { echo " Routes Found:\n"; foreach (array_slice($routes, 0, 3) as $route) { echo " - {$route->method->value} {$route->path} -> {$route->class->getShortName()}::{$route->handler->toString()}\n"; } } echo "\nāœ… Discovery refactoring test completed successfully!\n"; echo "\nšŸŽÆ Key Improvements:\n"; echo " āœ… Separated concerns into focused components\n"; echo " āœ… Shared reflection context (no duplication)\n"; echo " āœ… Stream-based processing for memory efficiency\n"; echo " āœ… Modern value object architecture\n"; echo " āœ… Improved caching strategy\n"; echo " āœ… Better error handling and logging\n"; } catch (Throwable $e) { echo "\nāŒ Error during discovery test:\n"; echo " Message: " . $e->getMessage() . "\n"; echo " File: " . $e->getFile() . ":" . $e->getLine() . "\n"; echo " Stack trace:\n" . $e->getTraceAsString() . "\n"; exit(1); }