From f0cfe4eda76616cf65dca6f4599d96a547319222 Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Sun, 15 Sep 2024 18:00:02 +0800 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=BD=D0=B5=D1=81=20=D1=80=D0=BE?= =?UTF-8?q?=D1=83=D1=82=D1=8B=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=B9=20=D1=84=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/Core/Bootstrapper.php | 47 ++++------------------------------- src/config/routes.php | 16 ++++++++++++ src/public/index.php | 9 +++---- 3 files changed, 24 insertions(+), 48 deletions(-) create mode 100644 src/config/routes.php diff --git a/src/app/Core/Bootstrapper.php b/src/app/Core/Bootstrapper.php index 0cb8cff..c0f2291 100644 --- a/src/app/Core/Bootstrapper.php +++ b/src/app/Core/Bootstrapper.php @@ -5,12 +5,9 @@ declare(strict_types=1); namespace App\Core; use App\Controllers\AjaxController; -use App\Controllers\HomeController; -use App\Controllers\PlaylistController; use App\Extensions\TwigFunctions; use Flight; use Illuminate\Support\Arr; -use Symfony\Component\Dotenv\Dotenv; use Twig\Environment; use Twig\Extension\DebugExtension; use Twig\Loader\FilesystemLoader; @@ -20,16 +17,6 @@ use Twig\Loader\FilesystemLoader; */ final class Bootstrapper { - /** - * Загружает env-переменные - * - * @return void - */ - public static function bootEnv(): void - { - (new Dotenv())->loadEnv(root_path() . '/.env'); - } - /** * Загружает конфигурацию приложения в контейнер * @@ -45,7 +32,7 @@ final class Bootstrapper } /** - * Загружает шаблонизатор и его расщирения + * Загружает шаблонизатор и его расширения * * @return void */ @@ -72,33 +59,9 @@ final class Bootstrapper */ public static function bootRoutes(): void { - Flight::route( - 'GET /', - fn() => (new HomeController())->index() - ); - Flight::route( - 'GET /page/@page:[0-9]+', - fn($page) => (new HomeController())->index((int)$page) - ); - Flight::route( - 'GET /faq', - fn() => (new HomeController())->faq() - ); - Flight::route( - 'GET /@id:[a-zA-Z0-9_-]+', - fn($id) => (new PlaylistController())->download($id) - ); - Flight::route( - 'GET /?[a-zA-Z0-9_-]+', - fn($id) => (new PlaylistController())->download($id) - ); - Flight::route( - 'GET /@id:[a-zA-Z0-9_-]+/details', - fn($id) => (new PlaylistController())->details($id) - ); - Flight::route( - 'GET /@id:[a-zA-Z0-9_-]+/json', - fn($id) => (new PlaylistController())->json($id) - ); + $routes = require_once config_path('routes.php'); + foreach ($routes as $route => $handler) { + Flight::route($route, $handler); + } } } diff --git a/src/config/routes.php b/src/config/routes.php new file mode 100644 index 0000000..0ae2acb --- /dev/null +++ b/src/config/routes.php @@ -0,0 +1,16 @@ + (new HomeController())->index(...), + 'GET /page/@page:[0-9]+' => (new HomeController())->index(...), + 'GET /faq' => (new HomeController())->faq(...), + 'GET /@id:[a-zA-Z0-9_-]+' => (new PlaylistController())->download(...), + 'GET /?[a-zA-Z0-9_-]+' => (new PlaylistController())->download(...), + 'GET /@id:[a-zA-Z0-9_-]+/details' => (new PlaylistController())->details(...), + 'GET /@id:[a-zA-Z0-9_-]+/json' => (new PlaylistController())->json(...), +]; diff --git a/src/public/index.php b/src/public/index.php index 046f1ce..b9db04e 100644 --- a/src/public/index.php +++ b/src/public/index.php @@ -3,6 +3,7 @@ declare(strict_types=1); use App\Core\Bootstrapper; +use Symfony\Component\Dotenv\Dotenv; /* |-------------------------------------------------------------------------- @@ -14,7 +15,7 @@ use App\Core\Bootstrapper; require '../vendor/autoload.php'; // load .env parameters -Bootstrapper::bootEnv(); +(new Dotenv())->loadEnv(root_path() . '/.env'); // set up framework according to its config Bootstrapper::bootSettings(); @@ -25,9 +26,5 @@ Bootstrapper::bootTwig(); // set up routes defined in config file Bootstrapper::bootRoutes(); -/* -|-------------------------------------------------------------------------- -| Start application -|-------------------------------------------------------------------------- -*/ +// start application Flight::start();