diff --git a/Classes/Service/TypoScriptSettingsService.php b/Classes/Service/TypoScriptSettingsService.php index b4d5ad1f71c0e42d06152a0f247145ad3e4e09ea..96a179ea760920a12754542b3bfd43402d199274 100644 --- a/Classes/Service/TypoScriptSettingsService.php +++ b/Classes/Service/TypoScriptSettingsService.php @@ -27,8 +27,10 @@ namespace SGalinski\SgMail\Service; ***************************************************************/ use TYPO3\CMS\Core\SingletonInterface; +use TYPO3\CMS\Core\TypoScript\TypoScriptService; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager; -use TYPO3\CMS\Extbase\Service\TypoScriptService; +use TYPO3\CMS\Extbase\Object\ObjectManager; /** * Returns the typoscript setup based on the page id @@ -36,7 +38,6 @@ use TYPO3\CMS\Extbase\Service\TypoScriptService; */ class TypoScriptSettingsService implements SingletonInterface { /** - * @inject * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface */ protected $objectManager; @@ -46,6 +47,13 @@ class TypoScriptSettingsService implements SingletonInterface { */ protected static $typoScriptCache = []; + /** + * Initializes the class + */ + public function __construct() { + $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class); + } + /** * Returns the typoscript settings of a given page and extension * @@ -53,26 +61,21 @@ class TypoScriptSettingsService implements SingletonInterface { * @param string $extensionKey * @return array */ - public function getSettings($pageId, $extensionKey) { + public function getSettings($pageId, $extensionKey): array { $pageId = (int) $pageId; - if (!isset(self::$typoScriptCache[$extensionKey . $pageId])) { + $cacheHash = $extensionKey . $pageId; + if (!isset(self::$typoScriptCache[$cacheHash])) { $tmpId = $_POST['id']; $_POST['id'] = $pageId; - /** @var TypoScriptService $typoScriptService */ - $class = 'TYPO3\CMS\Extbase\Service\TypoScriptService'; - $typoScriptService = $this->objectManager->get($class); - - /** @var BackendConfigurationManager $configurationManager */ - $class = 'TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager'; - $configurationManager = $this->objectManager->get($class); - - self::$typoScriptCache[$extensionKey . $pageId] = $typoScriptService->convertTypoScriptArrayToPlainArray( + $typoScriptService = $this->objectManager->get(TypoScriptService::class); + $configurationManager = $this->objectManager->get(BackendConfigurationManager::class); + self::$typoScriptCache[$cacheHash] = $typoScriptService->convertTypoScriptArrayToPlainArray( (array) $configurationManager->getTypoScriptSetup()['module.'][$extensionKey . '.']['settings.'] ); $_POST['id'] = $tmpId; } - return self::$typoScriptCache[$extensionKey . $pageId]; + return self::$typoScriptCache[$cacheHash]; } }