From 0b49de5d902e3880d8ea5ef9a5958b648331d73b Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Sun, 15 Sep 2024 19:37:31 +0800 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BD=D1=8B=20=D0=BB?= =?UTF-8?q?=D0=B8=D1=88=D0=BD=D0=B8=D0=B5=20=D0=B5=D0=BD=D0=B2=D1=8B=20PAG?= =?UTF-8?q?E=5FSIZE=20=D0=B8=20SORT=5FBY?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/.env.example | 2 -- src/app/Controllers/HomeController.php | 24 +++++---------- src/app/helpers.php | 41 +++---------------------- src/config/app.php | 2 -- src/{ => public/favicon}/favicon.ico | Bin 5 files changed, 12 insertions(+), 57 deletions(-) rename src/{ => public/favicon}/favicon.ico (100%) diff --git a/src/.env.example b/src/.env.example index 1d980e5..de4c437 100644 --- a/src/.env.example +++ b/src/.env.example @@ -5,5 +5,3 @@ TWIG_DEBUG=0 FLIGHT_CASE_SENSITIVE=0 FLIGHT_HANDLE_ERRORS=1 FLIGHT_LOG_ERRORS=1 -PAGE_SIZE=10 -SORT_BY= diff --git a/src/app/Controllers/HomeController.php b/src/app/Controllers/HomeController.php index 8d67ab3..bed4388 100644 --- a/src/app/Controllers/HomeController.php +++ b/src/app/Controllers/HomeController.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace App\Controllers; use App\Core\PlaylistProcessor; +use App\Core\RedirectedPlaylist; use Exception; use Flight; @@ -26,17 +27,6 @@ class HomeController extends Controller $this->ini = new PlaylistProcessor(); } - /** - * Возвращает размер одной страницы списка плейлистов - * - * @return int Указанный в конфиге размер либо 10, если он выходит за диапазоны от 5 до 100 - */ - protected function getPageSize(): int - { - $size = config('app.page_size'); - return empty($size) || $size < 5 || $size > 100 ? 10 : $size; - } - /** * Отображает главную страницу на указанной странице списка плейлистов * @@ -52,13 +42,13 @@ class HomeController extends Controller Flight::redirect(base_url($id)); die; } + // иначе формируем и сортируем список при необходимости, рисуем страницу - $per_page = $this->getPageSize(); - $list = $this->ini->playlists->where('redirect_id', null); - if ($sort_by = config('app.sort_by')) { - $list = $list->sortBy($sort_by); - } - $list = $list->forPage($page, $per_page); + $per_page = 10; + $list = $this->ini->playlists + ->filter(static fn ($playlist) => !($playlist instanceof RedirectedPlaylist)) + ->forPage($page, $per_page); + view('list', [ 'updated_at' => $this->ini->updatedAt(), 'count' => $this->ini->playlists->count(), diff --git a/src/app/helpers.php b/src/app/helpers.php index 8a7ccc9..e3b1f1f 100644 --- a/src/app/helpers.php +++ b/src/app/helpers.php @@ -17,17 +17,6 @@ function root_path(string $path = ''): string return rtrim(sprintf('%s/%s', dirname($_SERVER['DOCUMENT_ROOT']), $path), '/'); } -/** - * Returns path to app - * - * @param string $path - * @return string - */ -function app_path(string $path = ''): string -{ - return root_path("app/$path"); -} - /** * Return path to application configuration directory * @@ -50,17 +39,6 @@ function cache_path(string $path = ''): string return root_path("cache/$path"); } -/** - * Return path to public part of application - * - * @param string $path - * @return string - */ -function public_path(string $path = ''): string -{ - return root_path("public/$path"); -} - /** * Returns path to app views * @@ -137,23 +115,14 @@ function app(): Engine */ function bool(mixed $value): bool { - if (is_bool($value)) { - return $value; - } - if (is_object($value)) { + is_string($value) && $value = strtolower(trim($value)); + if (in_array($value, [true, 1, '1', '+', 'y', 'yes', 'on', 'true', 'enable', 'enabled'], true)) { return true; } - if (is_string($value)) { - return match ($value = trim($value)) { - '1', 'yes', 'true' => true, - '0', 'no', 'false' => false, - default => empty($value), - }; + if (in_array($value, [false, 0, '0', '-', 'n', 'no', 'off', 'false', 'disable', 'disabled'], true)) { + return false; } - if ($is_resource = is_resource($value)) { - return $is_resource; // false if closed - } - return !empty($value); + return (bool)$value; } /** diff --git a/src/config/app.php b/src/config/app.php index 380a5bc..7188cd0 100644 --- a/src/config/app.php +++ b/src/config/app.php @@ -26,7 +26,5 @@ return [ // 'CP866', // 'ISO-8859-5', ], - 'page_size' => (int)(env('PAGE_SIZE', 10)), - 'sort_by' => env('SORT_BY'), ], ]; diff --git a/src/favicon.ico b/src/public/favicon/favicon.ico similarity index 100% rename from src/favicon.ico rename to src/public/favicon/favicon.ico