diff --git a/src/LogViewer.php b/src/LogViewer.php index 53d256f..9d7575b 100644 --- a/src/LogViewer.php +++ b/src/LogViewer.php @@ -73,12 +73,29 @@ class LogViewer */ public function __construct($basePath, $dir, $file = null) { - $this->basePath = rtrim($basePath, '/'); + $this->basePath = $this->getRealPath(rtrim($basePath, '/')); $this->currentDirectory = $this->formatPath(rtrim($dir, '/')); $this->file = $this->formatPath($file); $this->files = new Filesystem(); } + protected function getRealPath($path) + { + $paths = explode('/', $path); + + $result = ''; + foreach ($paths as $v) { + $result .= $v.'/'; + + $current = rtrim($result, '/'); + if (is_link($current)) { + $result = readlink($current).'/'; + } + } + + return rtrim($result, '/'); + } + protected function formatPath($path) { return str_replace(['../'], '', $path); @@ -165,7 +182,7 @@ class LogViewer return $this->getLogBasePath(); } - return $this->getLogBasePath() . '/' . $this->currentDirectory; + return $this->getLogBasePath().'/'.$this->currentDirectory; } /**