Completed
Pull Request — master (#132)
by
unknown
11:17
created
Classes/Service/RegExRepService.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -11,44 +11,44 @@
 block discarded – undo
11 11
  */
12 12
 class RegExRepService implements \TYPO3\CMS\Core\SingletonInterface
13 13
 {
14
-    public function process(string $html): string
15
-    {
16
-        $config = array_intersect_key($GLOBALS['TSFE']->config['config']['replacer.'], ['search.' => null, 'replace.' => null]);
17
-
18
-        if (!isset($config['search.']) || !\is_array($config['search.'])) {
19
-            throw new \Exception('missing entry @ config.replacer.search');
20
-        }
21
-        if (!isset($config['replace.']) || !\is_array($config['replace.'])) {
22
-            throw new \Exception('missing entry @ config.replacer.replace');
23
-        }
24
-
25
-        foreach ($config as $section => &$block) {
26
-            foreach ($block as $key => &$regex) {
27
-                if ('search.' == $section
28
-                && (!\is_string($key) || '.' !== $key[-1])
29
-                && !preg_match('/^(.).+\1[a-z]*$/i', $regex)
30
-                ) {
31
-                    throw new \Exception("Please check your RegEx @ {$key} = {$regex}");
32
-                }
33
-                if (isset($config[$section][$key.'.'])) {
34
-                    $regex = $GLOBALS['TSFE']->cObj
35
-                        ->stdWrap(
36
-                            $regex,
37
-                            $config[$section][$key.'.']
38
-                        )
39
-                    ;
40
-                    unset($config[$section][$key.'.']); // keep!
41
-                }
42
-            }
43
-            ksort($config[$section]); // only for safety
44
-        }
45
-
46
-        $arrIntersectKeysCnt = 2 * \count(array_intersect_key($config['search.'], $config['replace.']));
47
-
48
-        if ((bool) (\count($config['search.']) + \count($config['replace.']) - $arrIntersectKeysCnt)) {
49
-            throw new \Exception('search/replace requests have diverged');
50
-        }
51
-
52
-        return preg_replace($config['search.'], $config['replace.'], $html);
53
-    }
14
+	public function process(string $html): string
15
+	{
16
+		$config = array_intersect_key($GLOBALS['TSFE']->config['config']['replacer.'], ['search.' => null, 'replace.' => null]);
17
+
18
+		if (!isset($config['search.']) || !\is_array($config['search.'])) {
19
+			throw new \Exception('missing entry @ config.replacer.search');
20
+		}
21
+		if (!isset($config['replace.']) || !\is_array($config['replace.'])) {
22
+			throw new \Exception('missing entry @ config.replacer.replace');
23
+		}
24
+
25
+		foreach ($config as $section => &$block) {
26
+			foreach ($block as $key => &$regex) {
27
+				if ('search.' == $section
28
+				&& (!\is_string($key) || '.' !== $key[-1])
29
+				&& !preg_match('/^(.).+\1[a-z]*$/i', $regex)
30
+				) {
31
+					throw new \Exception("Please check your RegEx @ {$key} = {$regex}");
32
+				}
33
+				if (isset($config[$section][$key.'.'])) {
34
+					$regex = $GLOBALS['TSFE']->cObj
35
+						->stdWrap(
36
+							$regex,
37
+							$config[$section][$key.'.']
38
+						)
39
+					;
40
+					unset($config[$section][$key.'.']); // keep!
41
+				}
42
+			}
43
+			ksort($config[$section]); // only for safety
44
+		}
45
+
46
+		$arrIntersectKeysCnt = 2 * \count(array_intersect_key($config['search.'], $config['replace.']));
47
+
48
+		if ((bool) (\count($config['search.']) + \count($config['replace.']) - $arrIntersectKeysCnt)) {
49
+			throw new \Exception('search/replace requests have diverged');
50
+		}
51
+
52
+		return preg_replace($config['search.'], $config['replace.'], $html);
53
+	}
54 54
 }
Please login to merge, or discard this patch.
Classes/Middleware/RegExRepMiddleware.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -19,29 +19,29 @@
 block discarded – undo
19 19
  */
20 20
 class RegExRepMiddleware implements MiddlewareInterface
21 21
 {
22
-    /**
23
-     * RegEx search & replace @ HTML output.
24
-     */
25
-    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
26
-    {
27
-        $response = $handler->handle($request);
22
+	/**
23
+	 * RegEx search & replace @ HTML output.
24
+	 */
25
+	public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
26
+	{
27
+		$response = $handler->handle($request);
28 28
 
29
-        if (!($response instanceof NullResponse)
30
-        && $GLOBALS['TSFE'] instanceof TypoScriptFrontendController
31
-        && $GLOBALS['TSFE']->cObj instanceof ContentObjectRenderer
32
-        && isset($GLOBALS['TSFE']->config['config']['replacer.'])
33
-        && 'text/html' == substr($response->getHeaderLine('Content-Type'), 0, 9)
34
-        && !empty($response->getBody())
35
-        ) {
36
-            $processedHtml = GeneralUtility::makeInstance(\HTML\Sourceopt\Service\RegExRepService::class)
37
-                ->process((string) $response->getBody())
38
-            ;
29
+		if (!($response instanceof NullResponse)
30
+		&& $GLOBALS['TSFE'] instanceof TypoScriptFrontendController
31
+		&& $GLOBALS['TSFE']->cObj instanceof ContentObjectRenderer
32
+		&& isset($GLOBALS['TSFE']->config['config']['replacer.'])
33
+		&& 'text/html' == substr($response->getHeaderLine('Content-Type'), 0, 9)
34
+		&& !empty($response->getBody())
35
+		) {
36
+			$processedHtml = GeneralUtility::makeInstance(\HTML\Sourceopt\Service\RegExRepService::class)
37
+				->process((string) $response->getBody())
38
+			;
39 39
 
40
-            $responseBody = new Stream('php://temp', 'rw');
41
-            $responseBody->write($processedHtml);
42
-            $response = $response->withBody($responseBody);
43
-        }
40
+			$responseBody = new Stream('php://temp', 'rw');
41
+			$responseBody->write($processedHtml);
42
+			$response = $response->withBody($responseBody);
43
+		}
44 44
 
45
-        return $response;
46
-    }
45
+		return $response;
46
+	}
47 47
 }
Please login to merge, or discard this patch.