好吧,我深信不疑。
我的问题的解决方案是迭代get_ini('include_path')
每个包含$fileName
的,转换为绝对路径并相应地处理。对我的自定义包括类的最小更改,真的。类加载器不需要任何更改。
感谢您的及时答复!
以下是我的包含器类的相关更新方法:( $this->includePath 初始化为 get_ini('include_path') )
// Pre-condition for includeFile()
// checks if $fileName exists in the include path
public function mayIncludeFile($fileName)
{
if(array_key_exists($fileName, $this->includeMap))
{
return TRUE;
}
if($fileName{0} == DIRECTORY_SEPARATOR)
{
if(is_file($fileName))
{
$this->includeMap[$fileName] = $fileName;
return TRUE;
}
}
else foreach($this->includePath as $index => $path)
{
$absoluteFileName = $path . DIRECTORY_SEPARATOR . $fileName;
if(is_file($absoluteFileName))
{
$this->includeMap[$fileName] = $absoluteFileName;
return TRUE;
}
}
return FALSE;
}
public function includeFile($fileName)
{
$this->validateFileName($fileName, TRUE);
if((array_key_exists($fileName, $this->includeMap) && $this->includeMap[$fileName]) ||
$this->mayIncludeFile($fileName))
{
include_once($this->includeMap[$fileName]);
}
}