diff --git a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php index 8b31ca0..b224eda 100644 --- a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php +++ b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php @@ -55,27 +55,26 @@ public function __construct() public function setFolder($folder) { if (app('files')->exists($folder)) { - + $this->folder = $folder; - } - else if(is_array($this->storage_path)) { - + } else if (is_array($this->storage_path)) { + foreach ($this->storage_path as $value) { - + $logsPath = $value . '/' . $folder; - + if (app('files')->exists($logsPath)) { $this->folder = $folder; break; } } } else { - - $logsPath = $this->storage_path . '/' . $folder; - if (app('files')->exists($logsPath)) { - $this->folder = $folder; - } - + + $logsPath = $this->storage_path . '/' . $folder; + if (app('files')->exists($logsPath)) { + $this->folder = $folder; + } + } } @@ -101,11 +100,11 @@ public function pathToLogFile($file) { if (app('files')->exists($file)) { // try the absolute path - + return $file; } if (is_array($this->storage_path)) { - + foreach ($this->storage_path as $folder) { if (app('files')->exists($folder . '/' . $file)) { // try the absolute path $file = $folder . '/' . $file; @@ -120,9 +119,9 @@ public function pathToLogFile($file) $file = $logsPath . '/' . $file; // check if requested file is really in the logs directory if (dirname($file) !== $logsPath) { - throw new \Exception('No such log file: '.$file); + throw new \Exception('No such log file: ' . $file); } - + return $file; } @@ -236,47 +235,47 @@ public function all() } /**Creates a multidimensional array - * of subdirectories and files - * - * @param null $path - * - * @return array - */ + * of subdirectories and files + * + * @param null $path + * + * @return array + */ public function foldersAndFiles($path = null) { - $contents = array(); - $dir = $path ? $path : $this->storage_path; - foreach (scandir($dir) as $node) { - if ($node == '.' || $node == '..') continue; - $path = $dir . '\\' . $node; - if (is_dir($path)) { - $contents[$path] = $this->foldersAndFiles($path); - } else { - $contents[] = $path; - } - } - - return $contents; + $contents = array(); + $dir = $path ? $path : $this->storage_path; + foreach (scandir($dir) as $node) { + if ($node == '.' || $node == '..') continue; + $path = $dir . '\\' . $node; + if (is_dir($path)) { + $contents[$path] = $this->foldersAndFiles($path); + } else { + $contents[] = $path; + } + } + + return $contents; } - /**Returns an array of - * all subdirectories of specified directory - * - * @param string $folder - * - * @return array - */ + /**Returns an array of + * all subdirectories of specified directory + * + * @param string $folder + * + * @return array + */ public function getFolders($folder = '') { - $folders = []; - $listObject = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($this->storage_path.'/'.$folder, \RecursiveDirectoryIterator::SKIP_DOTS), - \RecursiveIteratorIterator::CHILD_FIRST - ); - foreach ($listObject as $fileinfo) { - if($fileinfo->isDir()) $folders[] = $fileinfo->getRealPath(); - } - return $folders; + $folders = []; + $listObject = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($this->storage_path . '/' . $folder, \RecursiveDirectoryIterator::SKIP_DOTS), + \RecursiveIteratorIterator::CHILD_FIRST + ); + foreach ($listObject as $fileinfo) { + if ($fileinfo->isDir()) $folders[] = $fileinfo->getRealPath(); + } + return $folders; } @@ -297,77 +296,78 @@ public function getFolderFiles($basename = false) public function getFiles($basename = false, $folder = '') { $files = []; - $pattern = function_exists('config') ? config('logviewer.pattern', '*.log') : '*.log'; - $fullPath = $this->storage_path.'/'.$folder; + $pattern = function_exists('config') ? config('logviewer.pattern', '*.log') : '*.log'; + $fullPath = $this->storage_path . '/' . $folder; + + $listObject = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($fullPath, \RecursiveDirectoryIterator::SKIP_DOTS), + \RecursiveIteratorIterator::CHILD_FIRST + ); - $listObject = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($fullPath, \RecursiveDirectoryIterator::SKIP_DOTS), - \RecursiveIteratorIterator::CHILD_FIRST - ); + foreach ($listObject as $fileinfo) { + if (!$fileinfo->isDir() && strtolower(pathinfo($fileinfo->getRealPath(), PATHINFO_EXTENSION)) == explode('.', $pattern)[1]) + $files[] = $basename ? basename($fileinfo->getRealPath()) : $fileinfo->getRealPath(); + } - foreach ($listObject as $fileinfo) { - if(!$fileinfo->isDir() && strtolower(pathinfo($fileinfo->getRealPath(), PATHINFO_EXTENSION)) == explode('.', $pattern)[1]) - $files[] = $basename ? basename($fileinfo->getRealPath()) : $fileinfo->getRealPath(); - } - return $files; + arsort($files); + return array_values($files); } /** - * @return string - */ + * @return string + */ public function getStoragePath() { - return $this->storage_path; + return $this->storage_path; } - /** - * @param $path - * - * @return void - */ - public function setStoragePath($path) - { - $this->storage_path = $path; - } + /** + * @param $path + * + * @return void + */ + public function setStoragePath($path) + { + $this->storage_path = $path; + } public static function directoryTreeStructure($storage_path, array $array) { - foreach ($array as $k => $v) { - if(is_dir( $k )) { + foreach ($array as $k => $v) { + if (is_dir($k)) { - $exploded = explode( "\\", $k ); - $show = last( $exploded ); + $exploded = explode("\\", $k); + $show = last($exploded); - echo '