[TASK] Instantiate csConv directly instead of accessing the parent class 75/45375/2
authorBenni Mack <benni@typo3.org>
Sat, 19 Dec 2015 20:38:49 +0000 (21:38 +0100)
committerBenni Mack <benni@typo3.org>
Wed, 23 Dec 2015 13:21:34 +0000 (14:21 +0100)
There are several places in the core which checks
if CharsetConverter is available already, but since
the CharsetConverter is not related to the context,
the code can be simplified.

Resolves: #72336
Releases: master
Change-Id: I2665d77c1936b3e3504269de6c2f12746741e89e
Reviewed-on: https://review.typo3.org/45375
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Thomas Schlumberger <thomas@b13.de>
Tested-by: Thomas Schlumberger <thomas@b13.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Classes/Localization/Parser/AbstractXmlParser.php
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
typo3/sysext/core/Classes/Utility/File/BasicFileUtility.php

index 947277c..801c44e 100644 (file)
@@ -22,7 +22,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
 /**
  * Abstract class for XML based parser.
  */
-abstract class AbstractXmlParser implements \TYPO3\CMS\Core\Localization\Parser\LocalizationParserInterface
+abstract class AbstractXmlParser implements LocalizationParserInterface
 {
     /**
      * @var string
@@ -52,7 +52,7 @@ abstract class AbstractXmlParser implements \TYPO3\CMS\Core\Localization\Parser\
     {
         $this->sourcePath = $sourcePath;
         $this->languageKey = $languageKey;
-        $this->charset = $this->getCharset($languageKey, $charset);
+        $this->charset = $this->getCharset($charset);
         if ($this->languageKey !== 'default') {
             $this->sourcePath = GeneralUtility::getFileAbsFileName(GeneralUtility::llXmlAutoFileName($this->sourcePath, $this->languageKey));
             if (!@is_file($this->sourcePath)) {
@@ -71,26 +71,16 @@ abstract class AbstractXmlParser implements \TYPO3\CMS\Core\Localization\Parser\
     /**
      * Gets the character set to use.
      *
-     * @param string $languageKey
      * @param string $charset
      * @return string
      */
-    protected function getCharset($languageKey, $charset = '')
+    protected function getCharset($charset = '')
     {
-        /** @var $charsetConverter CharsetConverter */
-        if (is_object($GLOBALS['LANG'])) {
-            $charsetConverter = $GLOBALS['LANG']->csConvObj;
-        } elseif (is_object($GLOBALS['TSFE'])) {
-            $charsetConverter = $GLOBALS['TSFE']->csConvObj;
-        } else {
-            $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
-        }
         if ($charset !== '') {
-            $targetCharset = $charsetConverter->parse_charset($charset);
+            return GeneralUtility::makeInstance(CharsetConverter::class)->parse_charset($charset);
         } else {
-            $targetCharset = 'utf-8';
+            return 'utf-8';
         }
-        return $targetCharset;
     }
 
     /**
index d628ad8..812522f 100644 (file)
@@ -1361,15 +1361,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver
     protected function getCharsetConversion()
     {
         if (!isset($this->charsetConversion)) {
-            if (TYPO3_MODE === 'FE') {
-                $this->charsetConversion = $GLOBALS['TSFE']->csConvObj;
-            } elseif (is_object($GLOBALS['LANG'])) {
-                // BE assumed:
-                $this->charsetConversion = $GLOBALS['LANG']->csConvObj;
-            } else {
-                // The object may not exist yet, so we need to create it now. Happens in the Install Tool for example.
-                $this->charsetConversion = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
-            }
+            $this->charsetConversion = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
         }
         return $this->charsetConversion;
     }
index 7913bae..e1058d9 100644 (file)
@@ -401,15 +401,7 @@ class BasicFileUtility
         } else {
             // Get conversion object or initialize if needed
             if (!is_object($this->csConvObj)) {
-                if (TYPO3_MODE == 'FE') {
-                    $this->csConvObj = $GLOBALS['TSFE']->csConvObj;
-                } elseif (is_object($GLOBALS['LANG'])) {
-                    // BE assumed:
-                    $this->csConvObj = $GLOBALS['LANG']->csConvObj;
-                } else {
-                    // The object may not exist yet, so we need to create it now. Happens in the Install Tool for example.
-                    $this->csConvObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
-                }
+                $this->csConvObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
             }
             // Define character set
             if (!$charset) {