この habratopikを読んだ後。 クラスだけでなく、転送された他のファイルも再帰的に検索できるオートローダークラス(便利な場合があります)を共有することにしました。ファイルがそこにない場所で見つかった場合、対応するメッセージを生成し、ネームスペースの操作方法を認識し、必要に応じてそのアクションを記録します。
<?php namespace youNameSpace { /** * * * , .<br/> * , <br/> * ,<br/> * ( ), . * * @author : * @version 1.0 * @copyright: */ class Autoloader { /** *, * * @var type const * */ const debug = 0; public function __construct() { ; } public static function autoload($file, $ext = FALSE, $dir = FALSE) { $file = str_replace('\\', '/', $file); if($ext === FALSE) { $path = $_SERVER['DOCUMENT_ROOT'] . '/classes'; $filepath = $_SERVER['DOCUMENT_ROOT'] . '/classes/' . $file . '.php'; } else { $path = $_SERVER['DOCUMENT_ROOT'] . (($dir) ? '/' . $dir : ''); $filepath = $path . '/' . $file . '.' . $ext; } if (file_exists($filepath)) { if($ext === FALSE) { if(Autoloader::debug) Autoloader::StPutFile((' ' .$filepath)); require_once($filepath); } else { if(Autoloader::debug) Autoloader::StPutFile((' ' .$filepath)); return $filepath; } } else { $flag = true; if(Autoloader::debug) Autoloader::StPutFile((' <b>' . $file . '</b> <b>' . $path . '</b>')); return Autoloader::recursive_autoload($file, $path, $ext, $flag); } } public static function recursive_autoload($file, $path, $ext, &$flag) { if (FALSE !== ($handle = opendir($path)) && $flag) { while (FAlSE !== ($dir = readdir($handle)) && $flag) { if (strpos($dir, '.') === FALSE) { $path2 = $path .'/' . $dir; $filepath = $path2 . '/' . $file .(($ext === FALSE) ? '.php' : '.' . $ext); if(Autoloader::debug) Autoloader::StPutFile((' <b>' .$file .'</b> in ' .$filepath)); if (file_exists($filepath)) { $flag = FALSE; if($ext === FALSE) { if(Autoloader::debug) Autoloader::StPutFile((' ' .$filepath )); require_once($filepath); break; } else { if(Autoloader::debug) Autoloader::StPutFile((' ' .$filepath )); return $filepath; } } $res = Autoloader::recursive_autoload($file, $path2, $ext, $flag); } } closedir($handle); } return $res; } private static function StPutFile($data) { $dir = $_SERVER['DOCUMENT_ROOT'] .'/Log/Log.html'; $file = fopen($dir, 'a'); flock($file, LOCK_EX); fwrite($file, ('║' .$data .'=>' .date('dmY H:i:s') .'<br/>║<br/>' .PHP_EOL)); flock($file, LOCK_UN); fclose ($file); } } \spl_autoload_register('youNameSpace\Autoloader::autoload'); } ?>