Commit 819df0e4 authored by Tino Goratsch's avatar Tino Goratsch

fixed the JS file import logic for the ESI included page fragments

parent 9c100641
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Application\Bootstrap;
use ACP3\Core\View\Renderer\Smarty\Filters\MoveToBottom;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* Class HttpCache
* @package ACP3\Core\Application\Bootstrap
*/
class HttpCache extends \Symfony\Component\HttpKernel\HttpCache\HttpCache
{
const JAVASCRIPTS_REGEX_PATTERN = MoveToBottom::ELEMENT_CATCHER_REGEX_PATTERN;
const PLACEHOLDER = '</body>';
/**
* {@inheritdoc}
*/
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
$response = parent::handle($request, $type, $catch);
$this->moveStaticAssetsAround($response);
return $response;
}
/**
* @param Response $response
*/
private function moveStaticAssetsAround(Response $response)
{
$content = $response->getContent();
if (strpos($content, static::PLACEHOLDER) !== false) {
$content = str_replace(
static::PLACEHOLDER,
$this->addElementsFromTemplates($content) . "\n" . static::PLACEHOLDER,
$this->getCleanedUpTemplateOutput($content)
);
$response->setContent($content);
$response->headers->set('Content-Length', strlen($content));
}
}
/**
* @param string $tplOutput
* @return string
*/
private function getCleanedUpTemplateOutput($tplOutput)
{
return preg_replace(static::JAVASCRIPTS_REGEX_PATTERN, '', $tplOutput);
}
/**
* @param string $tplOutput
* @return string
*/
private function addElementsFromTemplates($tplOutput)
{
$matches = [];
preg_match_all(static::JAVASCRIPTS_REGEX_PATTERN, $tplOutput, $matches);
return implode("\n", array_unique($matches[1])) . "\n";
}
}
......@@ -40,7 +40,7 @@ trait CacheResponseTrait
if ($this->getUser()->isAuthenticated() || $this->getApplicationMode() === ApplicationMode::DEVELOPMENT) {
$response->setPrivate();
$lifetime = 0;
$lifetime = null;
}
$response
......
......@@ -26,4 +26,6 @@
</div>
</div>
</form>
{include_js module="system" file="ajax-form"}
{javascripts}
{include_js module="system" file="ajax-form"}
{/javascripts}
......@@ -27,7 +27,7 @@ $cacheStore = new \Symfony\Component\HttpKernel\HttpCache\Store(
$kernel->getAppPath()->getCacheDir() . 'http/'
);
$appCache = new \Symfony\Component\HttpKernel\HttpCache\HttpCache(
$appCache = new \ACP3\Core\Application\Bootstrap\HttpCache(
$kernel,
$cacheStore,
new \Symfony\Component\HttpKernel\HttpCache\Esi(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment