mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-18 00:09:06 +01:00
LSsession::includeFile(): improve logging
This commit is contained in:
parent
ee74eed4b8
commit
f223827157
2 changed files with 41 additions and 16 deletions
|
@ -151,33 +151,33 @@ class LSsession {
|
|||
$path = ($external?'':LS_ROOT_DIR."/").$file;
|
||||
$local_path = ($external?'':LS_ROOT_DIR."/").LS_LOCAL_DIR.$file;
|
||||
$path = (file_exists($local_path)?$local_path:$path);
|
||||
if ($path[0] != '/') {
|
||||
if (!isAbsolutePath($path)) {
|
||||
$found = stream_resolve_include_path($path);
|
||||
if ($found === false) {
|
||||
if (!$warn)
|
||||
return false;
|
||||
$log_msg = "includeFile($file, external=$external) : file $path not found in include path.";
|
||||
if (class_exists('LSlog'))
|
||||
self :: log_warning($log_msg);
|
||||
else
|
||||
error_log($log_msg);
|
||||
self :: log(
|
||||
($warn?'WARNING':'TRACE'),
|
||||
"includeFile($file, external=$external) : file $path not found in include path."
|
||||
);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
self :: log_trace("includeFile($file, external=$external): file path found using include path => '$found'");
|
||||
$path = $found;
|
||||
}
|
||||
}
|
||||
else if (!file_exists($path)) {
|
||||
if (!$warn)
|
||||
return false;
|
||||
$log_msg = "includeFile($file, external=$external) : file not found ($local_path / $path)";
|
||||
if (class_exists('LSlog'))
|
||||
self :: log_warning($log_msg);
|
||||
else
|
||||
error_log($log_msg);
|
||||
self :: log(
|
||||
($warn?'WARNING':'TRACE'),
|
||||
"includeFile($file, external=$external): file not found ($local_path / $path)"
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return include_once($path);
|
||||
if (!include_once($path)) {
|
||||
// Always log as warning in this case
|
||||
self :: log_warning("includeFile($file, external=$external): include_once($path) not returned TRUE");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -669,6 +669,31 @@ function LSdebugDefined() {
|
|||
return "unknown : ".(string)$callable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a path is absolute
|
||||
*
|
||||
* @param[in] $path string The path
|
||||
*
|
||||
* @retval boolean True if path is absolute, False otherwise
|
||||
*/
|
||||
function isAbsolutePath($path) {
|
||||
return strStartWith($path, '/') || strStartWith($path, './') || strStartWith($path, '../');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string start with another specified string
|
||||
*
|
||||
* @param[in] $string string The string to search in
|
||||
* @param[in] $start_string string The starting string to check
|
||||
*
|
||||
* @retval boolean True if string start by specified one, False otherwise
|
||||
*/
|
||||
function strStartWith($string, $start_string) {
|
||||
if (strlen($start_string) > strlen($string))
|
||||
return false;
|
||||
return substr($string, 0, strlen($start_string)) === $start_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump file content
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue