Remove html compression middleware
This commit is contained in:
@@ -1,54 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace EP\EpTheme\Middleware;
|
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Psr\Http\Server\MiddlewareInterface;
|
|
||||||
use Psr\Http\Server\RequestHandlerInterface;
|
|
||||||
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
|
|
||||||
use TYPO3\CMS\Core\Http\StreamFactory;
|
|
||||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
||||||
use WyriHaximus\HtmlCompress\Factory;
|
|
||||||
|
|
||||||
class HtmlCompress implements MiddlewareInterface
|
|
||||||
{
|
|
||||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
|
||||||
{
|
|
||||||
$response = $handler->handle($request);
|
|
||||||
|
|
||||||
$compressionEnabled = GeneralUtility::makeInstance(ExtensionConfiguration::class)
|
|
||||||
->get('ep_theme', 'compressHtml');
|
|
||||||
|
|
||||||
if (false === (bool)$compressionEnabled || $this->isTypeNumSet($request)) {
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
$stream = $response->getBody();
|
|
||||||
$stream->rewind();
|
|
||||||
$content = $stream->getContents();
|
|
||||||
$newBody = (new StreamFactory())->createStream($this->compressHtml($content));
|
|
||||||
$response = $response->withBody($newBody);
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function compressHtml(string $html): string
|
|
||||||
{
|
|
||||||
$parser = Factory::construct();
|
|
||||||
$html = $parser->compress($html);
|
|
||||||
$html = $this->removeComments($html);
|
|
||||||
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function removeComments(string $html): string
|
|
||||||
{
|
|
||||||
return preg_replace('/<!--((?!TYPO3SEARCH)[\s\S])*?-->/', '', $html);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function isTypeNumSet(ServerRequestInterface $request): bool
|
|
||||||
{
|
|
||||||
return $request->getAttribute('routing')->getPageType() > 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,14 +8,5 @@ return [
|
|||||||
'typo3/cms-frontend/site',
|
'typo3/cms-frontend/site',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'ep/html-compress' => [
|
|
||||||
'target' => \EP\EpTheme\Middleware\HtmlCompress::class,
|
|
||||||
'before' => [
|
|
||||||
'typo3/cms-frontend/output-compression'
|
|
||||||
],
|
|
||||||
'after' => [
|
|
||||||
'typo3/cms-adminpanel/renderer'
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user