1
0
mirror of https://github.com/typemill/typemill.git synced 2025-08-04 21:27:41 +02:00

moved assets to middleware for proxy detection

This commit is contained in:
trendschau
2020-10-18 08:50:58 +02:00
parent 1e6c42c98a
commit a3167a26ee
15 changed files with 183 additions and 83 deletions

View File

@@ -0,0 +1,40 @@
<?php
namespace Typemill\Middleware;
use Slim\Views\Twig;
use Slim\Http\Request;
use Slim\Http\Response;
class assetMiddleware
{
protected $view;
protected $c;
public function __construct($container)
{
# $this->view = $view;
$this->container = $container;
}
public function __invoke(Request $request, Response $response, $next)
{
# get the uri after proxy detection
$uri = $request->getUri()->withUserInfo('');
# update the asset object in the container (for plugins) with the new url
$this->container->assets->setBaseUrl($uri->getBaseUrl());
# add the asset object to twig-frontend for themes
$this->container['view']->getEnvironment()->addGlobal('assets', $this->container['assets']);
# use {{ base_url() }} in twig templates
$this->container['view']['base_url'] = $uri->getBaseUrl();
$this->container['view']['current_url'] = $uri->getPath();
$response = $next($request, $response);
return $response;
}
}