mirror of
https://github.com/anthonyaxenov/iptv.git
synced 2024-12-21 13:55:37 +00:00
Вынес роуты в отдельный файл
This commit is contained in:
parent
8483dc586e
commit
f0cfe4eda7
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
16
src/config/routes.php
Normal file
16
src/config/routes.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Controllers\HomeController;
|
||||
use App\Controllers\PlaylistController;
|
||||
|
||||
return [
|
||||
'GET /' => (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(...),
|
||||
];
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user