set order to desc for logs viewer

This commit is contained in:
小喵 2022-10-20 20:52:50 +08:00
parent db313f5eef
commit 976e10659f
Signed by: mt
GPG key ID: CD321C269EC63BB6
4 changed files with 21 additions and 3 deletions

View file

@ -4,6 +4,8 @@ namespace MingTsay\Akanyan;
abstract class FileViewer
{
protected static bool $orderDesc = false;
protected abstract static function directory(): string;
protected abstract static function whitelist(): ?array;
@ -13,10 +15,13 @@ abstract class FileViewer
$directory = static::directory();
$whitelist = static::whitelist();
return array_values(array_filter(
$list = array_values(array_filter(
scandir($directory),
fn($file) => ($whitelist === null || in_array($file, $whitelist)) && is_file("$directory/$file")
));
if (static::$orderDesc) rsort($list);
return $list;
}
public static function read($file): ?string

View file

@ -4,6 +4,7 @@ namespace MingTsay\Akanyan;
class LogsViewer extends FileViewer
{
protected static bool $orderDesc = true;
protected static function directory(): string
{