Code cleanup

This commit is contained in:
Pierre Rudloff 2020-10-19 22:24:59 +02:00
parent da93835ea2
commit e2560cd9cb
2 changed files with 10 additions and 10 deletions

View file

@ -8,6 +8,7 @@ namespace Alltube;
use Psr\Container\ContainerInterface;
use Slim\Http\Request;
use Slim\Http\Uri;
use Slim\Views\Smarty;
use Slim\Views\SmartyPlugins;
use SmartyException;
@ -34,31 +35,29 @@ class ViewFactory
$view = new Smarty(__DIR__ . '/../templates/');
/** @var Uri $uri */
$uri = $request->getUri();
if (in_array('https', $request->getHeader('X-Forwarded-Proto'))) {
$uri = $uri->withScheme('https')->withPort(443);
}
// set values from X-Forwarded-* headers
$host = current($request->getHeader('X-Forwarded-Host'));
if ($host) {
if ($host = current($request->getHeader('X-Forwarded-Host'))) {
$uri = $uri->withHost($host);
}
$port = current($request->getHeader('X-Forwarded-Port'));
if ($port) {
if ($port = current($request->getHeader('X-Forwarded-Port'))) {
$uri = $uri->withPort(intVal($port));
}
$path = current($request->getHeader('X-Forwarded-Path'));
if ($path) {
if ($path = current($request->getHeader('X-Forwarded-Path'))) {
$uri = $uri->withBasePath($path);
}
/** @var LocaleManager $localeManager */
$localeManager = $container->get('locale');
$smartyPlugins = new SmartyPlugins($container->get('router'), $uri->withUserInfo(null));
$smartyPlugins = new SmartyPlugins($container->get('router'), $uri->withUserInfo(''));
$view->registerPlugin('function', 'path_for', [$smartyPlugins, 'pathFor']);
$view->registerPlugin('function', 'base_url', [$smartyPlugins, 'baseUrl']);
$view->registerPlugin('block', 't', [$localeManager, 'smartyTranslate']);

View file

@ -33,15 +33,16 @@ try {
// Locales.
$container['locale'] = LocaleManagerFactory::create();
$app->add(new LocaleMiddleware($container));
$app->add(new RouterPathMiddleware($container));
// Smarty.
$container['view'] = ViewFactory::create($container);
// Logger.
$container['logger'] = LoggerFactory::create($container);
// Middlewares.
$app->add(new LocaleMiddleware($container));
$app->add(new RouterPathMiddleware($container));
// Controllers.
$frontController = new FrontController($container);
$jsonController = new JsonController($container);