Skip to content

Commit 9bcd0e8

Browse files
authored
Merge pull request #137 from xerc/master
[FIX] missing cObj @ replacer
2 parents 2e26a23 + 8dd3a5a commit 9bcd0e8

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Classes/Middleware/RegExRepMiddleware.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use TYPO3\CMS\Core\Http\NullResponse;
1212
use TYPO3\CMS\Core\Http\Stream;
1313
use TYPO3\CMS\Core\Utility\GeneralUtility;
14-
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
1514
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
1615

1716
/**
@@ -28,8 +27,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
2827

2928
if (!($response instanceof NullResponse)
3029
&& $GLOBALS['TSFE'] instanceof TypoScriptFrontendController
31-
&& $GLOBALS['TSFE']->cObj instanceof ContentObjectRenderer
32-
&& isset($GLOBALS['TSFE']->config['config']['replacer.'])
30+
&& ($GLOBALS['TSFE']->config['config']['replacer.'] ?? false)
3331
&& 'text/html' == substr($response->getHeaderLine('Content-Type'), 0, 9)
3432
&& !empty($response->getBody())
3533
) {

Classes/Service/RegExRepService.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace HTML\Sourceopt\Service;
66

7+
use TYPO3\CMS\Core\Utility\GeneralUtility;
8+
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
9+
710
/**
811
* Class RegExRepService.
912
*
@@ -21,8 +24,10 @@ public function process(string $html): string
2124
}
2225

2326
if (preg_match_all('/"([\w\-]+)\.";/', serialize(array_keys($config[$section])), $matches)) {
27+
$cObj = $cObj ?? $GLOBALS['TSFE']->cObj ?? GeneralUtility::makeInstance(ContentObjectRenderer::class);
28+
2429
foreach ($matches[1] as $key) {
25-
$config[$section][$key] = $GLOBALS['TSFE']->cObj
30+
$config[$section][$key] = $cObj
2631
->stdWrap(
2732
$config[$section][$key],
2833
$config[$section][$key.'.']
@@ -32,8 +37,9 @@ public function process(string $html): string
3237
}
3338
}
3439

35-
ksort($config[$section], \SORT_NATURAL); // for safety only
40+
ksort($config[$section], \SORT_NATURAL); // safety
3641
}
42+
unset($cObj, $matches); // save MEM
3743

3844
if (\TYPO3\CMS\Core\Core\Environment::getContext()->isDevelopment()) {
3945
foreach ($config['search.'] as $key => $val) {

0 commit comments

Comments
 (0)