getExtension() === 'php') { $relativePath = str_replace([$baseDir, '/', '.php'], ['', '\\', ''], $file->getPathname()); $className = $namespace . '\\' . $relativePath; $className = str_replace('\\\\', '\\', $className); // Remove double backslashes $allClasses[$className] = $file->getPathname(); } } // Separate loaded and not loaded $classDetails = []; foreach ($allClasses as $className => $path) { $status = class_exists($className, true) ? 'Loaded' : 'Not Loaded'; $classDetails[] = [ 'class' => self::getClassNameOnly($className), 'path' => $path, 'status' => $status, ]; } return $classDetails; } /** * Extract the class name from a fully qualified class name. * * @param string $class Fully qualified class name. * @return string The class name without the namespace. */ private static function getClassNameOnly(string $class): string { $parts = explode('\\', $class); return end($parts); } /** * Display the results in a table format. * * @param string $namespace The namespace to inspect. * @param string $baseDir The base directory for the namespace. * @param bool $useHtml Whether to generate the table as HTML (default: true). * @return void */ public static function displayClassTable(string $namespace, string $baseDir, bool $useHtml = true): void { $classDetails = self::compareLoadedClasses($namespace, $baseDir); if ($useHtml) { // Generate HTML table echo ""; echo ""; echo ""; echo ""; echo ""; foreach ($classDetails as $detail) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo ""; echo "
ClassPathStatus
{$detail['class']}{$detail['path']}{$detail['status']}
"; } else { // Generate plain text table echo str_pad("Class", 30) . str_pad("Path", 50) . "Status\n"; echo str_repeat("-", 100) . "\n"; foreach ($classDetails as $detail) { echo str_pad($detail['class'], 30) . str_pad($detail['path'], 50) . $detail['status'] . "\n"; } } } /** * Debug all classes in the top-level namespace, showing a table of results. * * @param bool $useHtml Whether to generate the table as HTML (default: true). * @return void */ public static function debugTopLevelNamespace(bool $useHtml = true): void { $namespace = self::getTopLevelNamespace(); if (!$namespace) { echo "Top-level namespace could not be determined.\n"; return; } // Assume PSR-4 base directory is app/ (adjust if needed) $baseDir = realpath(__DIR__ . '/../../app'); if (!$baseDir) { echo "Base directory could not be resolved.\n"; return; } self::displayClassTable($namespace, $baseDir, $useHtml); } }