alltube/index.php

96 lines
2.3 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
use Alltube\ConfigFactory;
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;
use Alltube\LocaleManagerFactory;
2017-05-29 19:11:59 +00:00
use Alltube\LocaleMiddleware;
use Alltube\LoggerFactory;
use Alltube\RouterPathMiddleware;
use Alltube\ViewFactory;
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();
$app->add(new LocaleMiddleware($container));
$app->add(new RouterPathMiddleware($container));
2019-11-27 20:22:23 +00:00
// Smarty.
2020-05-13 20:33:02 +00:00
$container['view'] = ViewFactory::create($container);
// Logger.
$container['logger'] = LoggerFactory::create($container);
// 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);
}