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 "
| Class | Path | Status |
|---|---|---|
| {$detail['class']} | "; echo "{$detail['path']} | "; echo "{$detail['status']} | "; echo "