alltube/index.php

101 lines
2.6 KiB
PHP
Raw Normal View History

2016-08-01 16:04:44 +00:00
<?php
2016-09-07 22:28:28 +00:00
require_once __DIR__ . '/vendor/autoload.php';
2020-05-13 20:57:25 +00:00
2019-04-22 15:04:59 +00:00
use Alltube\Controller\DownloadController;
2017-01-10 22:39:58 +00:00
use Alltube\Controller\FrontController;
use Alltube\Controller\JsonController;
2020-10-18 10:03:57 +00:00
use Alltube\ErrorHandler;
2020-10-20 21:29:50 +00:00
use Alltube\Factory\ConfigFactory;
use Alltube\Factory\LocaleManagerFactory;
use Alltube\Factory\LoggerFactory;
use Alltube\Factory\ViewFactory;
2020-10-20 21:13:48 +00:00
use Alltube\Middleware\CspMiddleware;
use Alltube\Middleware\LinkHeaderMiddleware;
use Alltube\Middleware\LocaleMiddleware;
use Alltube\Middleware\RouterPathMiddleware;
use Slim\App;
2020-05-13 20:28:05 +00:00
use Slim\Container;
2015-10-29 20:19:40 +00:00
2016-10-26 15:16:17 +00:00
if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) {
header('Location: ' . str_ireplace('/index.php', '/', $_SERVER['REQUEST_URI']));
2016-07-27 00:19:29 +00:00
die;
}
try {
// Create app.
$app = new App();
/** @var Container $container */
$container = $app->getContainer();
2020-05-13 20:28:05 +00:00
// Config.
2020-10-17 22:59:19 +00:00
$container['config'] = ConfigFactory::create($container);
// Locales.
$container['locale'] = LocaleManagerFactory::create();
// Smarty.
2020-05-13 20:33:02 +00:00
$container['view'] = ViewFactory::create($container);
// Logger.
$container['logger'] = LoggerFactory::create($container);
2020-10-19 20:24:59 +00:00
// Middlewares.
$app->add(new LocaleMiddleware($container));
$app->add(new CspMiddleware($container));
$app->add(new LinkHeaderMiddleware($container));
$app->add(new RouterPathMiddleware($container));
2020-10-19 20:24:59 +00:00
// Controllers.
$frontController = new FrontController($container);
$jsonController = new JsonController($container);
$downloadController = new DownloadController($container);
// Error handling.
$container['errorHandler'] = [$frontController, 'error'];
$container['phpErrorHandler'] = [$frontController, 'error'];
2020-07-15 21:17:23 +00:00
$container['notFoundHandler'] = [$frontController, 'notFound'];
$container['notAllowedHandler'] = [$frontController, 'notAllowed'];
// Routes.
$app->get(
'/',
[$frontController, 'index']
)->setName('index');
$app->get(
'/extractors',
[$frontController, 'extractors']
)->setName('extractors');
$app->any(
'/info',
[$frontController, 'info']
)->setName('info');
$app->any(
'/watch',
[$frontController, 'info']
);
$app->any(
'/download',
[$downloadController, 'download']
)->setName('download');
$app->get(
'/locale/{locale}',
[$frontController, 'locale']
)->setName('locale');
$app->get(
'/json',
[$jsonController, 'json']
)->setName('json');
$app->run();
2020-05-13 20:33:02 +00:00
} catch (Throwable $e) {
2020-10-18 10:03:57 +00:00
ErrorHandler::handle($e);
}