From 5454a72063e56ef6bee10ec51b0177f30f6b17b8 Mon Sep 17 00:00:00 2001
From: Stefan Galinski <stefan@sgalinski.de>
Date: Sun, 18 Nov 2018 22:14:17 +0100
Subject: [PATCH] [BUGFIX] Fix missing object exception on the live (strange,
 that this wasn't visible on the dev)

---
 Classes/Service/TypoScriptSettingsService.php | 31 ++++++++++---------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/Classes/Service/TypoScriptSettingsService.php b/Classes/Service/TypoScriptSettingsService.php
index b4d5ad1f..96a179ea 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];
 	}
 }
-- 
GitLab