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();