2016-08-01 16:04:44 +00:00
|
|
|
<?php
|
2016-09-07 22:28:28 +00:00
|
|
|
|
2019-10-03 19:24:12 +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;
|
2019-04-22 14:05:58 +00:00
|
|
|
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;
|
2017-04-25 22:50:19 +00:00
|
|
|
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) {
|
2019-10-03 19:24:12 +00:00
|
|
|
header('Location: ' . str_ireplace('/index.php', '/', $_SERVER['REQUEST_URI']));
|
2016-07-27 00:19:29 +00:00
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
2020-07-15 21:05:41 +00:00
|
|
|
try {
|
|
|
|
// Create app.
|
|
|
|
$app = new App();
|
2019-04-21 16:30:02 +00:00
|
|
|
|
2020-07-15 21:05:41 +00:00
|
|
|
/** @var Container $container */
|
|
|
|
$container = $app->getContainer();
|
2020-05-13 20:28:05 +00:00
|
|
|
|
2020-07-15 21:05:41 +00:00
|
|
|
// Config.
|
2020-10-17 22:59:19 +00:00
|
|
|
$container['config'] = ConfigFactory::create($container);
|
2019-11-28 00:04:07 +00:00
|
|
|
|
2020-07-15 21:05:41 +00:00
|
|
|
// Locales.
|
|
|
|
$container['locale'] = LocaleManagerFactory::create();
|
2020-10-19 20:18:03 +00:00
|
|
|
|
2020-07-15 21:05:41 +00:00
|
|
|
// Smarty.
|
2020-05-13 20:33:02 +00:00
|
|
|
$container['view'] = ViewFactory::create($container);
|
2019-11-27 22:15:49 +00:00
|
|
|
|
2020-07-15 21:05:41 +00:00
|
|
|
// Logger.
|
|
|
|
$container['logger'] = LoggerFactory::create($container);
|
|
|
|
|
2020-10-19 20:24:59 +00:00
|
|
|
// Middlewares.
|
|
|
|
$app->add(new LocaleMiddleware($container));
|
2020-10-19 21:43:33 +00:00
|
|
|
$app->add(new CspMiddleware($container));
|
2020-10-20 21:10:14 +00:00
|
|
|
$app->add(new LinkHeaderMiddleware($container));
|
2020-10-20 21:49:23 +00:00
|
|
|
$app->add(new RouterPathMiddleware($container));
|
2020-10-19 20:24:59 +00:00
|
|
|
|
2020-07-15 21:05:41 +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'];
|
2020-07-15 21:05:41 +00:00
|
|
|
|
|
|
|
// 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');
|
2019-04-22 14:05:58 +00:00
|
|
|
|
2017-10-02 19:07:13 +00:00
|
|
|
$app->run();
|
2020-05-13 20:33:02 +00:00
|
|
|
} catch (Throwable $e) {
|
2020-10-18 10:03:57 +00:00
|
|
|
ErrorHandler::handle($e);
|
2017-10-02 19:07:13 +00:00
|
|
|
}
|