私はディレクトリの任意のレベルからクラスを見つけるためにこの機能を持っています
function _findFile($path, $class) {
$founded_file = "";
$dir = scandir($path);
foreach ($dir as $file) {
$current_path = $path . $file;
// echo $current_path . "\n";
if ($file != "." && $file != "..") {
// echo $current_path . "\n";
if (is_dir($current_path)) {
return $this->_findFile($current_path . "/", $class);
} else if (is_file($current_path) && end(explode(".", $current_path)) === "php") {
if (end(explode("/", $current_path)) === ($class . ".php")) {
return $current_path;
}
}
}
}
return $founded_file;
}
私のディレクトリ構造
system
-base
-core.php
-exceptions.php
-database
-database.php
ファイルが見つかりませんsystem > database
最初のコメントのコメントを外すと、関数がsystem > database
パスに入っていないことがわかります
疑問があれば聞いてください