@@ -16,46 +16,46 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class RegExRepService implements SingletonInterface |
| 18 | 18 | { |
| 19 | - public function process(string $html): string |
|
| 20 | - { |
|
| 21 | - $config = $GLOBALS['TSFE']->config['config']['replacer.']; |
|
| 22 | - |
|
| 23 | - foreach (['search.', 'replace.'] as $section) { |
|
| 24 | - if (!isset($config[$section]) || !\is_array($config[$section])) { |
|
| 25 | - throw new \Exception('missing entry @ config.replacer.' . $section); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - if (preg_match_all('/"([\w\-]+)\.";/', serialize(array_keys($config[$section])), $matches)) { |
|
| 29 | - $cObj ??= ($GLOBALS['TSFE']->cObj ?? GeneralUtility::makeInstance(ContentObjectRenderer::class)); |
|
| 30 | - |
|
| 31 | - foreach ($matches[1] as $key) { |
|
| 32 | - $config[$section][$key] = $cObj |
|
| 33 | - ->stdWrap( |
|
| 34 | - $config[$section][$key], |
|
| 35 | - $config[$section][$key . '.'] |
|
| 36 | - ) |
|
| 37 | - ; |
|
| 38 | - unset($config[$section][$key . '.']); // keep! |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - ksort($config[$section], \SORT_NATURAL); // safety |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - if (Environment::getContext()->isDevelopment()) { |
|
| 46 | - foreach ($config['search.'] as $key => $val) { |
|
| 47 | - if (false === @preg_match($val, '')) { |
|
| 48 | - throw new \Exception(preg_last_error_msg() . ' : please check your regex syntax @ ' . "{$key} = {$val}"); |
|
| 49 | - } |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - $arrIntersectKeysCnt = 2 * \count(array_intersect_key($config['search.'], $config['replace.'])); |
|
| 54 | - |
|
| 55 | - if ((bool) (\count($config['search.']) + \count($config['replace.']) - $arrIntersectKeysCnt)) { |
|
| 56 | - throw new \Exception('config.replacer requests have diverged'); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - return preg_replace($config['search.'], $config['replace.'], $html); |
|
| 60 | - } |
|
| 19 | + public function process(string $html): string |
|
| 20 | + { |
|
| 21 | + $config = $GLOBALS['TSFE']->config['config']['replacer.']; |
|
| 22 | + |
|
| 23 | + foreach (['search.', 'replace.'] as $section) { |
|
| 24 | + if (!isset($config[$section]) || !\is_array($config[$section])) { |
|
| 25 | + throw new \Exception('missing entry @ config.replacer.' . $section); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + if (preg_match_all('/"([\w\-]+)\.";/', serialize(array_keys($config[$section])), $matches)) { |
|
| 29 | + $cObj ??= ($GLOBALS['TSFE']->cObj ?? GeneralUtility::makeInstance(ContentObjectRenderer::class)); |
|
| 30 | + |
|
| 31 | + foreach ($matches[1] as $key) { |
|
| 32 | + $config[$section][$key] = $cObj |
|
| 33 | + ->stdWrap( |
|
| 34 | + $config[$section][$key], |
|
| 35 | + $config[$section][$key . '.'] |
|
| 36 | + ) |
|
| 37 | + ; |
|
| 38 | + unset($config[$section][$key . '.']); // keep! |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + ksort($config[$section], \SORT_NATURAL); // safety |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + if (Environment::getContext()->isDevelopment()) { |
|
| 46 | + foreach ($config['search.'] as $key => $val) { |
|
| 47 | + if (false === @preg_match($val, '')) { |
|
| 48 | + throw new \Exception(preg_last_error_msg() . ' : please check your regex syntax @ ' . "{$key} = {$val}"); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + $arrIntersectKeysCnt = 2 * \count(array_intersect_key($config['search.'], $config['replace.'])); |
|
| 54 | + |
|
| 55 | + if ((bool) (\count($config['search.']) + \count($config['replace.']) - $arrIntersectKeysCnt)) { |
|
| 56 | + throw new \Exception('config.replacer requests have diverged'); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + return preg_replace($config['search.'], $config['replace.'], $html); |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -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 | } |
@@ -14,44 +14,44 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class SvgFileRepository |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Retrieves all used SVGs within given storage-array. |
|
| 19 | - */ |
|
| 20 | - public function findAllByStorageUids(array $storageUids): \Traversable |
|
| 21 | - { |
|
| 22 | - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file'); |
|
| 17 | + /** |
|
| 18 | + * Retrieves all used SVGs within given storage-array. |
|
| 19 | + */ |
|
| 20 | + public function findAllByStorageUids(array $storageUids): \Traversable |
|
| 21 | + { |
|
| 22 | + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file'); |
|
| 23 | 23 | |
| 24 | - return $queryBuilder |
|
| 25 | - ->select('sys_file.storage', 'sys_file.identifier', 'sys_file.sha1') |
|
| 26 | - ->from('sys_file') |
|
| 27 | - ->innerJoin( |
|
| 28 | - 'sys_file', |
|
| 29 | - 'sys_file_reference', |
|
| 30 | - 'sys_file_reference', |
|
| 31 | - $queryBuilder->expr()->eq( |
|
| 32 | - 'sys_file_reference.uid_local', |
|
| 33 | - $queryBuilder->quoteIdentifier('sys_file.uid') |
|
| 34 | - ) |
|
| 35 | - ) |
|
| 36 | - ->where( |
|
| 37 | - $queryBuilder->expr()->in( |
|
| 38 | - 'sys_file.storage', |
|
| 39 | - $queryBuilder->createNamedParameter($storageUids, \TYPO3\CMS\Core\Database\Connection::PARAM_INT_ARRAY) |
|
| 40 | - ), |
|
| 41 | - $queryBuilder->expr()->lt( |
|
| 42 | - 'sys_file.size', |
|
| 43 | - $queryBuilder->createNamedParameter((int) ($GLOBALS['TSFE']->config['config']['svgstore.']['fileSize'] ?? null), \TYPO3\CMS\Core\Database\Connection::PARAM_INT) |
|
| 44 | - ), |
|
| 45 | - $queryBuilder->expr()->eq( |
|
| 46 | - 'sys_file.mime_type', |
|
| 47 | - $queryBuilder->createNamedParameter('image/svg+xml', \TYPO3\CMS\Core\Database\Connection::PARAM_STR) |
|
| 48 | - ) |
|
| 49 | - ) |
|
| 50 | - ->groupBy('sys_file.uid', 'sys_file.storage', 'sys_file.identifier', 'sys_file.sha1') |
|
| 51 | - ->orderBy('sys_file.storage') |
|
| 52 | - ->addOrderBy('sys_file.identifier') |
|
| 53 | - ->executeQuery() |
|
| 54 | - ->iterateAssociative() |
|
| 55 | - ; |
|
| 56 | - } |
|
| 24 | + return $queryBuilder |
|
| 25 | + ->select('sys_file.storage', 'sys_file.identifier', 'sys_file.sha1') |
|
| 26 | + ->from('sys_file') |
|
| 27 | + ->innerJoin( |
|
| 28 | + 'sys_file', |
|
| 29 | + 'sys_file_reference', |
|
| 30 | + 'sys_file_reference', |
|
| 31 | + $queryBuilder->expr()->eq( |
|
| 32 | + 'sys_file_reference.uid_local', |
|
| 33 | + $queryBuilder->quoteIdentifier('sys_file.uid') |
|
| 34 | + ) |
|
| 35 | + ) |
|
| 36 | + ->where( |
|
| 37 | + $queryBuilder->expr()->in( |
|
| 38 | + 'sys_file.storage', |
|
| 39 | + $queryBuilder->createNamedParameter($storageUids, \TYPO3\CMS\Core\Database\Connection::PARAM_INT_ARRAY) |
|
| 40 | + ), |
|
| 41 | + $queryBuilder->expr()->lt( |
|
| 42 | + 'sys_file.size', |
|
| 43 | + $queryBuilder->createNamedParameter((int) ($GLOBALS['TSFE']->config['config']['svgstore.']['fileSize'] ?? null), \TYPO3\CMS\Core\Database\Connection::PARAM_INT) |
|
| 44 | + ), |
|
| 45 | + $queryBuilder->expr()->eq( |
|
| 46 | + 'sys_file.mime_type', |
|
| 47 | + $queryBuilder->createNamedParameter('image/svg+xml', \TYPO3\CMS\Core\Database\Connection::PARAM_STR) |
|
| 48 | + ) |
|
| 49 | + ) |
|
| 50 | + ->groupBy('sys_file.uid', 'sys_file.storage', 'sys_file.identifier', 'sys_file.sha1') |
|
| 51 | + ->orderBy('sys_file.storage') |
|
| 52 | + ->addOrderBy('sys_file.identifier') |
|
| 53 | + ->executeQuery() |
|
| 54 | + ->iterateAssociative() |
|
| 55 | + ; |
|
| 56 | + } |
|
| 57 | 57 | } |