protected function xautoload_InjectedAPI_findFile::_fileExists_checkIncludePath in X Autoload 7.3
Same name and namespace in other branches
- 7.2 lib/InjectedAPI/findFile.php \xautoload_InjectedAPI_findFile::_fileExists_checkIncludePath()
Check if a file exists, considering the full include path.
Parameters
string $file: The filepath
Return value
boolean TRUE, if the file exists somewhere in include path.
1 call to xautoload_InjectedAPI_findFile::_fileExists_checkIncludePath()
- xautoload_InjectedAPI_findFile::suggestFile_checkIncludePath in lib/
InjectedAPI/ findFile.php - Same as suggestFile(), but check the full PHP include path.
File
- lib/
InjectedAPI/ findFile.php, line 140
Class
- xautoload_InjectedAPI_findFile
- To help testability, we use an injected API instead of just a return value. The injected API can be mocked to provide a mocked file_exists(), and to monitor all suggested candidates, not just the correct return value.
Code
protected function _fileExists_checkIncludePath($file) {
if (function_exists('stream_resolve_include_path')) {
// Use the PHP 5.3.1+ way of doing this.
return FALSE !== stream_resolve_include_path($file);
}
elseif ($file[0] === DIRECTORY_SEPARATOR) {
// That's an absolute path already.
return file_exists($file);
}
else {
// Manually loop all candidate paths.
foreach (explode(PATH_SEPARATOR, get_include_path()) as $base_dir) {
if (file_exists($base_dir . DIRECTORY_SEPARATOR . $file)) {
return TRUE;
}
}
return FALSE;
}
}