兼容软连接目录设置

This commit is contained in:
jqh 2020-07-13 14:43:29 +08:00
parent d65ff46fef
commit 9f9bf0af6c

View File

@ -73,12 +73,29 @@ class LogViewer
*/ */
public function __construct($basePath, $dir, $file = null) public function __construct($basePath, $dir, $file = null)
{ {
$this->basePath = rtrim($basePath, '/'); $this->basePath = $this->getRealPath(rtrim($basePath, '/'));
$this->currentDirectory = $this->formatPath(rtrim($dir, '/')); $this->currentDirectory = $this->formatPath(rtrim($dir, '/'));
$this->file = $this->formatPath($file); $this->file = $this->formatPath($file);
$this->files = new Filesystem(); $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) protected function formatPath($path)
{ {
return str_replace(['../'], '', $path); return str_replace(['../'], '', $path);
@ -165,7 +182,7 @@ class LogViewer
return $this->getLogBasePath(); return $this->getLogBasePath();
} }
return $this->getLogBasePath() . '/' . $this->currentDirectory; return $this->getLogBasePath().'/'.$this->currentDirectory;
} }
/** /**