[TASK] Deprecate $TSFE->csConvObj 49/47449/3
authorBenni Mack <benni@typo3.org>
Thu, 31 Mar 2016 07:18:52 +0000 (09:18 +0200)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Fri, 1 Apr 2016 09:29:19 +0000 (11:29 +0200)
The CharsetConverter class is now a singleton and not
depending on a context (FE/BE) as it always takes the
needed charset for conversion as parameter.

$LANG->csConv is already deprecated, this patch
cleans up the last bits inside TypoScriptFrontendController
and therefore deprecates $TSFE->csConvObj
and $TSFE->csConv().

Resolves: #75327
Releases: master
Change-Id: I9c69a7c7d7edc5bc9efd1bc206b0b05364824339
Reviewed-on: https://review.typo3.org/47449
Reviewed-by: Markus Sommer <markussom@posteo.de>
Tested-by: Markus Sommer <markussom@posteo.de>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
typo3/sysext/compatibility7/Classes/Controller/SearchFormController.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-75327-TSFE-csConvObjAndTSFE-csConv.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Tests/Unit/ContentObject/CaseContentObjectTest.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php
typo3/sysext/frontend/Tests/Unit/ContentObject/FilesContentObjectTest.php

index e110b85..a97c405 100755 (executable)
@@ -2315,7 +2315,7 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
     public function utf8_to_currentCharset($str)
     {
         GeneralUtility::logDeprecatedFunction();
-        return $this->frontendController->csConv($str, 'utf-8');
+        return $str;
     }
 
     /**
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-75327-TSFE-csConvObjAndTSFE-csConv.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-75327-TSFE-csConvObjAndTSFE-csConv.rst
new file mode 100644 (file)
index 0000000..9665f07
--- /dev/null
@@ -0,0 +1,34 @@
+==========================================================
+Deprecation: #75327 - $TSFE->csConvObj and $TSFE->csConv()
+==========================================================
+
+Description
+===========
+
+The public property "csConvObj" and the public method "csConv()" inside the TypoScriptFrontendController PHP
+class have been marked as deprecated.
+
+
+Impact
+======
+
+Calling ``$TSFE->csConv()`` will trigger a deprecation log entry.
+
+
+Affected Installations
+======================
+
+Any TYPO3 installation which uses the property or the method directly above.
+
+
+Migration
+=========
+
+If a charset conversion is necessary, the conversion can be done directly by instantiating the charset converter class.
+
+.. code-block:: php
+
+       $from = 'iso-8859-15';
+       /** @var \TYPO3\CMS\Core\Charset\CharsetConverter $charsetConverter */
+       $charsetConverter = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
+       $output = $charsetConverter->conv($str, $charsetConverter->parse_charset($from), 'utf-8');
\ No newline at end of file
index b3fc1be..ffe15de 100644 (file)
@@ -3827,12 +3827,13 @@ class ContentObjectRenderer
      */
     public function substring($content, $options)
     {
-        $tsfe = $this->getTypoScriptFrontendController();
+        /** @var CharsetConverter $charsetConverter */
+        $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
         $options = GeneralUtility::intExplode(',', $options . ',');
         if ($options[1]) {
-            return $tsfe->csConvObj->substr('utf-8', $content, $options[0], $options[1]);
+            return $charsetConverter->substr('utf-8', $content, $options[0], $options[1]);
         } else {
-            return $tsfe->csConvObj->substr('utf-8', $content, $options[0]);
+            return $charsetConverter->substr('utf-8', $content, $options[0]);
         }
     }
 
@@ -6779,22 +6780,23 @@ class ContentObjectRenderer
      */
     public function caseshift($theValue, $case)
     {
-        $tsfe = $this->getTypoScriptFrontendController();
+        /** @var CharsetConverter $charsetConverter */
+        $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
         switch (strtolower($case)) {
             case 'upper':
-                $theValue = $tsfe->csConvObj->conv_case('utf-8', $theValue, 'toUpper');
+                $theValue = $charsetConverter->conv_case('utf-8', $theValue, 'toUpper');
                 break;
             case 'lower':
-                $theValue = $tsfe->csConvObj->conv_case('utf-8', $theValue, 'toLower');
+                $theValue = $charsetConverter->conv_case('utf-8', $theValue, 'toLower');
                 break;
             case 'capitalize':
                 $theValue = ucwords($theValue);
                 break;
             case 'ucfirst':
-                $theValue = $tsfe->csConvObj->convCaseFirst('utf-8', $theValue, 'toUpper');
+                $theValue = $charsetConverter->convCaseFirst('utf-8', $theValue, 'toUpper');
                 break;
             case 'lcfirst':
-                $theValue = $tsfe->csConvObj->convCaseFirst('utf-8', $theValue, 'toLower');
+                $theValue = $charsetConverter->convCaseFirst('utf-8', $theValue, 'toLower');
                 break;
             case 'uppercamelcase':
                 $theValue = GeneralUtility::underscoredToUpperCamelCase($theValue);
index 91b9a38..cffab2c 100644 (file)
@@ -725,6 +725,7 @@ class TypoScriptFrontendController
      * charset conversion class. May be used by any application.
      *
      * @var CharsetConverter
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, instantiate CharsetConverter on your own if you need it
      */
     public $csConvObj;
 
@@ -4314,7 +4315,9 @@ class TypoScriptFrontendController
 
         // Rendering charset of HTML page.
         if ($this->config['config']['metaCharset']) {
-            $this->metaCharset = $this->csConvObj->parse_charset($this->config['config']['metaCharset']);
+            /** @var CharsetConverter $charsetConverter */
+            $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
+            $this->metaCharset = $charsetConverter->parse_charset($this->config['config']['metaCharset']);
         }
     }
 
@@ -4328,11 +4331,15 @@ class TypoScriptFrontendController
      * @param string $from Optional "from" charset.
      * @return string Output string, converted if needed.
      * @see CharsetConverter
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
      */
     public function csConv($str, $from = '')
     {
+        GeneralUtility::logDeprecatedFunction();
         if ($from) {
-            $output = $this->csConvObj->conv($str, $this->csConvObj->parse_charset($from), 'utf-8');
+            /** @var CharsetConverter $charsetConverter */
+            $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
+            $output = $charsetConverter->conv($str, $charsetConverter->parse_charset($from), 'utf-8');
             return $output ?: $str;
         } else {
             return $str;
@@ -4348,7 +4355,9 @@ class TypoScriptFrontendController
     public function convOutputCharset($content)
     {
         if ($this->metaCharset !== 'utf-8') {
-            $content = $this->csConvObj->conv($content, 'utf-8', $this->metaCharset, true);
+            /** @var CharsetConverter $charsetConverter */
+            $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
+            $content = $charsetConverter->conv($content, 'utf-8', $this->metaCharset, true);
         }
         return $content;
     }
@@ -4361,7 +4370,9 @@ class TypoScriptFrontendController
     public function convPOSTCharset()
     {
         if ($this->metaCharset !== 'utf-8' && is_array($_POST) && !empty($_POST)) {
-            $this->csConvObj->convArray($_POST, $this->metaCharset, 'utf-8');
+            /** @var CharsetConverter $charsetConverter */
+            $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
+            $charsetConverter->convArray($_POST, $this->metaCharset, 'utf-8');
             $GLOBALS['HTTP_POST_VARS'] = $_POST;
         }
     }
index 700e037..ecdf43e 100644 (file)
@@ -43,7 +43,6 @@ class CaseContentObjectTest extends UnitTestCase
         $tsfe->config = array();
         $tsfe->page = array();
         $tsfe->sys_page = $this->getMock(PageRepository::class, array('getRawRecord'));
-        $tsfe->csConvObj = new CharsetConverter();
         $GLOBALS['TSFE'] = $tsfe;
 
         $contentObjectRenderer = new ContentObjectRenderer();
index 4db80bc..d5cf253 100755 (executable)
@@ -102,7 +102,6 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $this->typoScriptFrontendControllerMock->config = array();
         $this->typoScriptFrontendControllerMock->page = array();
         $this->typoScriptFrontendControllerMock->sys_page = $pageRepositoryMock;
-        $this->typoScriptFrontendControllerMock->csConvObj = new CharsetConverter();
         $GLOBALS['TSFE'] = $this->typoScriptFrontendControllerMock;
         $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class, array());
 
index a40203b..06e4d95 100644 (file)
@@ -56,7 +56,6 @@ class FilesContentObjectTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $sysPageMock = $this->getMock(PageRepository::class, array('getRawRecord'));
         $this->tsfe->sys_page = $sysPageMock;
         $GLOBALS['TSFE'] = $this->tsfe;
-        $GLOBALS['TSFE']->csConvObj = new CharsetConverter();
 
         $contentObjectRenderer = new ContentObjectRenderer();
         $contentObjectRenderer->setContentObjectClassMap(array(