@@ -11,22 +11,22 @@ |
||
| 11 | 11 | |
| 12 | 12 | class SvgStoreMiddleware extends AbstractMiddleware |
| 13 | 13 | { |
| 14 | - public function __construct(protected SvgStoreService $svgStoreService) |
|
| 15 | - { |
|
| 16 | - } |
|
| 14 | + public function __construct(protected SvgStoreService $svgStoreService) |
|
| 15 | + { |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Search/Extract/Merge SVGs @ HTML output. |
|
| 20 | - */ |
|
| 21 | - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
| 22 | - { |
|
| 23 | - $response = $handler->handle($request); |
|
| 18 | + /** |
|
| 19 | + * Search/Extract/Merge SVGs @ HTML output. |
|
| 20 | + */ |
|
| 21 | + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
| 22 | + { |
|
| 23 | + $response = $handler->handle($request); |
|
| 24 | 24 | |
| 25 | - if ($this->responseIsAlterable($response) && $GLOBALS['TSFE']->config['config']['svgstore.']['enabled'] ?? false) { |
|
| 26 | - $processedHtml = $this->svgStoreService->process((string) $response->getBody()); |
|
| 27 | - $response = $response->withBody($this->getStringStream($processedHtml)); |
|
| 28 | - } |
|
| 25 | + if ($this->responseIsAlterable($response) && $GLOBALS['TSFE']->config['config']['svgstore.']['enabled'] ?? false) { |
|
| 26 | + $processedHtml = $this->svgStoreService->process((string) $response->getBody()); |
|
| 27 | + $response = $response->withBody($this->getStringStream($processedHtml)); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - return $response; |
|
| 31 | - } |
|
| 30 | + return $response; |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -11,25 +11,25 @@ |
||
| 11 | 11 | |
| 12 | 12 | class CleanHtmlMiddleware extends AbstractMiddleware |
| 13 | 13 | { |
| 14 | - public function __construct(protected CleanHtmlService $cleanHtmlService) |
|
| 15 | - { |
|
| 16 | - } |
|
| 14 | + public function __construct(protected CleanHtmlService $cleanHtmlService) |
|
| 15 | + { |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Clean the HTML output. |
|
| 20 | - */ |
|
| 21 | - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
| 22 | - { |
|
| 23 | - $response = $handler->handle($request); |
|
| 18 | + /** |
|
| 19 | + * Clean the HTML output. |
|
| 20 | + */ |
|
| 21 | + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
| 22 | + { |
|
| 23 | + $response = $handler->handle($request); |
|
| 24 | 24 | |
| 25 | - if ($this->responseIsAlterable($response) && $GLOBALS['TSFE']->config['config']['sourceopt.']['enabled'] ?? false) { |
|
| 26 | - $processedHtml = $this->cleanHtmlService->clean( |
|
| 27 | - (string) $response->getBody(), |
|
| 28 | - (array) $GLOBALS['TSFE']->config['config']['sourceopt.'] |
|
| 29 | - ); |
|
| 30 | - $response = $response->withBody($this->getStringStream($processedHtml)); |
|
| 31 | - } |
|
| 25 | + if ($this->responseIsAlterable($response) && $GLOBALS['TSFE']->config['config']['sourceopt.']['enabled'] ?? false) { |
|
| 26 | + $processedHtml = $this->cleanHtmlService->clean( |
|
| 27 | + (string) $response->getBody(), |
|
| 28 | + (array) $GLOBALS['TSFE']->config['config']['sourceopt.'] |
|
| 29 | + ); |
|
| 30 | + $response = $response->withBody($this->getStringStream($processedHtml)); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - return $response; |
|
| 34 | - } |
|
| 33 | + return $response; |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -11,22 +11,22 @@ |
||
| 11 | 11 | |
| 12 | 12 | class RegExRepMiddleware extends AbstractMiddleware |
| 13 | 13 | { |
| 14 | - public function __construct(protected RegExRepService $regExRepService) |
|
| 15 | - { |
|
| 16 | - } |
|
| 14 | + public function __construct(protected RegExRepService $regExRepService) |
|
| 15 | + { |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * RegEx search & replace @ HTML output. |
|
| 20 | - */ |
|
| 21 | - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
| 22 | - { |
|
| 23 | - $response = $handler->handle($request); |
|
| 18 | + /** |
|
| 19 | + * RegEx search & replace @ HTML output. |
|
| 20 | + */ |
|
| 21 | + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
| 22 | + { |
|
| 23 | + $response = $handler->handle($request); |
|
| 24 | 24 | |
| 25 | - if ($this->responseIsAlterable($response) && $GLOBALS['TSFE']->config['config']['replacer.'] ?? false) { |
|
| 26 | - $processedHtml = $this->regExRepService->process((string) $response->getBody()); |
|
| 27 | - $response = $response->withBody($this->getStringStream($processedHtml)); |
|
| 28 | - } |
|
| 25 | + if ($this->responseIsAlterable($response) && $GLOBALS['TSFE']->config['config']['replacer.'] ?? false) { |
|
| 26 | + $processedHtml = $this->regExRepService->process((string) $response->getBody()); |
|
| 27 | + $response = $response->withBody($this->getStringStream($processedHtml)); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - return $response; |
|
| 31 | - } |
|
| 30 | + return $response; |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -13,32 +13,32 @@ |
||
| 13 | 13 | |
| 14 | 14 | abstract class AbstractMiddleware implements MiddlewareInterface |
| 15 | 15 | { |
| 16 | - protected function responseIsAlterable(ResponseInterface $response): bool |
|
| 17 | - { |
|
| 18 | - if (!$response instanceof NullResponse) { |
|
| 19 | - return false; |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - if (!$GLOBALS['TSFE'] instanceof TypoScriptFrontendController) { // need for configuration |
|
| 23 | - return false; |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - if ('text/html' !== substr($response->getHeaderLine('Content-Type'), 0, 9)) { |
|
| 27 | - return false; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - if (empty($response->getBody())) { |
|
| 31 | - return false; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - return true; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - protected function getStringStream(string $content): StreamInterface |
|
| 38 | - { |
|
| 39 | - $body = new Stream('php://temp', 'rw'); |
|
| 40 | - $body->write($content); |
|
| 41 | - |
|
| 42 | - return $body; |
|
| 43 | - } |
|
| 16 | + protected function responseIsAlterable(ResponseInterface $response): bool |
|
| 17 | + { |
|
| 18 | + if (!$response instanceof NullResponse) { |
|
| 19 | + return false; |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + if (!$GLOBALS['TSFE'] instanceof TypoScriptFrontendController) { // need for configuration |
|
| 23 | + return false; |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + if ('text/html' !== substr($response->getHeaderLine('Content-Type'), 0, 9)) { |
|
| 27 | + return false; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + if (empty($response->getBody())) { |
|
| 31 | + return false; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + return true; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + protected function getStringStream(string $content): StreamInterface |
|
| 38 | + { |
|
| 39 | + $body = new Stream('php://temp', 'rw'); |
|
| 40 | + $body->write($content); |
|
| 41 | + |
|
| 42 | + return $body; |
|
| 43 | + } |
|
| 44 | 44 | } |