#!/usr/bin/env php getFilename(), '.') === 0) { continue; } if ($file->getExtension() !== 'php') { continue; } // abc\def.php $relativePath = str_replace(str_replace('/', '\\', $path . '\\'), '', str_replace('/', '\\', $file->getRealPath())); // app\command\abc $realNamespace = trim($namespace . '\\' . trim(dirname(str_replace('\\', DIRECTORY_SEPARATOR, $relativePath)), '.'), '\\'); $realNamespace = str_replace('/', '\\', $realNamespace); // app\command\doc\def $class_name = trim($realNamespace . '\\' . $file->getBasename('.php'), '\\'); if (!class_exists($class_name) || !is_a($class_name, Commands::class, true)) { continue; } $command = new $class_name; $application->add($command); } } $application->run();