Expose source path on LogFileInterface

Add LogFileInterface::getPath(): ?string so detectors can dispatch on a
filename hint when the original path is known. Default implementation on
the abstract LogFile base returns null; PathLogFile records its
constructor argument. StringLogFile and StreamLogFile inherit the null
default. Tests cover both the path and null-fallback cases.
This commit is contained in:
2026-04-30 20:29:21 +00:00
parent e709389e08
commit 8ae7da5259
5 changed files with 38 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ namespace IndifferentKetchup\Codex\Log\File;
abstract class LogFile implements LogFileInterface
{
protected ?string $content = null;
protected ?string $path = null;
/**
* Get the log file content
@@ -20,4 +21,14 @@ abstract class LogFile implements LogFileInterface
{
return $this->content;
}
/**
* Get the source path of the log file when one is known
*
* @return string|null
*/
public function getPath(): ?string
{
return $this->path;
}
}

View File

@@ -15,4 +15,15 @@ interface LogFileInterface
* @return string
*/
public function getContent(): string;
/**
* Get the source path of the log file when one is known
*
* Returns null for log files without a filesystem origin (string content,
* arbitrary streams). Concrete implementations should return the path used
* to construct them when applicable.
*
* @return string|null
*/
public function getPath(): ?string;
}

View File

@@ -22,6 +22,7 @@ class PathLogFile extends LogFile
throw new InvalidArgumentException("File '" . $path . "' not found.");
}
$this->path = $path;
$this->content = file_get_contents($path);
}
}