Add CLI Support #1
28
Logger.php
28
Logger.php
@ -20,6 +20,15 @@
|
||||
class Logger
|
||||
{
|
||||
|
||||
/**
|
||||
* Prüft, ob das Skript in der CLI läuft
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isCLI()
|
||||
{
|
||||
return PHP_SAPI === 'cli';
|
||||
}
|
||||
|
||||
/**
|
||||
* $log_file - path and log file name
|
||||
* @var string
|
||||
@ -295,19 +304,17 @@ class Logger
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert absolute path to relative url (using UNIX directory seperators)
|
||||
*
|
||||
* E.g.:
|
||||
* Input: D:\development\htdocs\public\todo-list\index.php
|
||||
* Output: localhost/todo-list/index.php
|
||||
*
|
||||
* @param string Absolute directory/path of file which should be converted to a relative (url) path
|
||||
* @return string Relative path
|
||||
* Konvertiert einen absoluten Pfad in einen relativen (unter Berücksichtigung von CLI)
|
||||
*/
|
||||
public static function absToRelPath($pathToConvert)
|
||||
{
|
||||
if (static::isCLI()) {
|
||||
return $pathToConvert; // In CLI einfach den absoluten Pfad zurückgeben
|
||||
}
|
||||
|
||||
$pathAbs = str_replace(['/', '\\'], '/', $pathToConvert);
|
||||
$documentRoot = str_replace(['/', '\\'], '/', $_SERVER['DOCUMENT_ROOT']);
|
||||
$documentRoot = str_replace(['/', '\\'], '/', $_SERVER['DOCUMENT_ROOT'] ?? '');
|
||||
|
||||
return $_SERVER['SERVER_NAME'] . str_replace($documentRoot, '', $pathAbs);
|
||||
}
|
||||
|
||||
@ -346,4 +353,5 @@ class Logger
|
||||
*/
|
||||
private function __destruct()
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user