refactor: Split FrontController into multiple classes

Closes #177
This commit is contained in:
Pierre Rudloff 2019-04-22 16:05:58 +02:00
parent 196d0b1338
commit 25f33bba56
10 changed files with 904 additions and 703 deletions

View file

@ -3,6 +3,8 @@
require_once __DIR__.'/vendor/autoload.php';
use Alltube\Config;
use Alltube\Controller\FrontController;
use Alltube\Controller\JsonController;
use Alltube\Controller\DownloadController;
use Alltube\LocaleManager;
use Alltube\LocaleMiddleware;
use Alltube\UglyRouter;
@ -32,49 +34,52 @@ if (!class_exists('Locale')) {
$container['locale'] = new LocaleManager($_COOKIE);
$app->add(new LocaleMiddleware($container));
$controller = new FrontController($container, $_COOKIE);
$frontController = new FrontController($container, $_COOKIE);
$jsonController = new JsonController($container, $_COOKIE);
$downloadController = new DownloadController($container, $_COOKIE);
$container['errorHandler'] = [$controller, 'error'];
$container['errorHandler'] = [$jsonController, 'error'];
$app->get(
'/',
[$controller, 'index']
[$frontController, 'index']
)->setName('index');
$app->get(
'/extractors',
[$controller, 'extractors']
[$frontController, 'extractors']
)->setName('extractors');
$app->any(
'/info',
[$controller, 'info']
[$frontController, 'info']
)->setName('info');
// Legacy route.
$app->any('/video', [$controller, 'info']);
$app->any('/video', [$frontController, 'info']);
$app->any(
'/watch',
[$controller, 'video']
[$frontController, 'video']
);
$app->get(
$app->any(
'/download',
[$controller, 'download']
[$downloadController, 'download']
)->setName('download');
// Legacy route.
$app->get('/redirect', [$controller, 'download']);
$app->get(
'/json',
[$controller, 'json']
)->setName('json');
$app->get('/redirect', [$downloadController, 'download']);
$app->get(
'/locale/{locale}',
[$controller, 'locale']
[$frontController, 'locale']
)->setName('locale');
$app->get(
'/json',
[$jsonController, 'json']
)->setName('json');
try {
$app->run();
} catch (SmartyException $e) {