[TASK] Deprecate methods strtolower & strtoupper of GeneralUtility 32/48832/5
authorGeorg Ringer <georg.ringer@gmail.com>
Wed, 6 Jul 2016 18:25:45 +0000 (20:25 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Sat, 9 Jul 2016 10:54:46 +0000 (12:54 +0200)
In favor of CharsetConverter and the native implementation, the
following methods of GeneralUtility have been deprecated:
- strtolower
- strtoupper

Resolves: #76804
Releases: master
Change-Id: I9516c6ec3aebb0a7fd07266d4b4491e4794edbd8
Reviewed-on: https://review.typo3.org/48832
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/compatibility7/Classes/Controller/SearchFormController.php
typo3/sysext/core/Classes/FrontendEditing/FrontendEditingController.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-76804-DeprecateGeneralUtilitystrtoupperStrtolower.rst [new file with mode: 0644]
typo3/sysext/dbal/Classes/Database/SqlCompilers/Adodb.php
typo3/sysext/extensionmanager/Classes/Utility/Connection/TerUtility.php
typo3/sysext/felogin/Classes/Controller/FrontendLoginController.php
typo3/sysext/lang/Classes/Service/TerService.php
typo3/sysext/rtehtmlarea/Classes/Extension/BlockElements.php
typo3/sysext/rtehtmlarea/Classes/Extension/ContextMenu.php

index a58c888..931d3cf 100755 (executable)
@@ -1334,7 +1334,7 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
         // Multilangual text
         $substituteArray = array('legend', 'searchFor', 'extResume', 'atATime', 'orderBy', 'fromSection', 'searchIn', 'match', 'style', 'freeIndexUid');
         foreach ($substituteArray as $marker) {
-            $markerArray['###FORM_' . GeneralUtility::strtoupper($marker) . '###'] = htmlspecialchars($this->pi_getLL('form_' . $marker));
+            $markerArray['###FORM_' . strtoupper($marker) . '###'] = htmlspecialchars($this->pi_getLL('form_' . $marker));
         }
         $markerArray['###FORM_SUBMIT###'] = htmlspecialchars($this->pi_getLL('submit_button_label'));
         // Adding search field value
@@ -1575,7 +1575,7 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
             }
             if (is_array($tmplContent)) {
                 foreach ($tmplContent as $k => $v) {
-                    $markerArray['###' . GeneralUtility::strtoupper($k) . '###'] = $v;
+                    $markerArray['###' . strtoupper($k) . '###'] = $v;
                 }
             }
             // Description text
index 81293b0..d1d7796 100755 (executable)
@@ -488,7 +488,7 @@ class FrontendEditingController
             }
             if (!$conf['onlyCurrentPid'] || $dataArray['pid'] == $GLOBALS['TSFE']->id) {
                 // Permissions:
-                $types = GeneralUtility::trimExplode(',', GeneralUtility::strtolower($conf['allow']), true);
+                $types = GeneralUtility::trimExplode(',', strtolower($conf['allow']), true);
                 $allow = array_flip($types);
                 $perms = $GLOBALS['BE_USER']->calcPerms($GLOBALS['TSFE']->page);
                 if ($table == 'pages') {
@@ -517,12 +517,12 @@ class FrontendEditingController
     protected function getAllowedEditActions($table, array $conf, $pid, $allow = '')
     {
         if (!$allow) {
-            $types = GeneralUtility::trimExplode(',', GeneralUtility::strtolower($conf['allow']), true);
+            $types = GeneralUtility::trimExplode(',', strtolower($conf['allow']), true);
             $allow = array_flip($types);
         }
         if (!$conf['onlyCurrentPid'] || $pid == $GLOBALS['TSFE']->id) {
             // Permissions
-            $types = GeneralUtility::trimExplode(',', GeneralUtility::strtolower($conf['allow']), true);
+            $types = GeneralUtility::trimExplode(',', strtolower($conf['allow']), true);
             $allow = array_flip($types);
             $perms = $GLOBALS['BE_USER']->calcPerms($GLOBALS['TSFE']->page);
             if ($table == 'pages') {
index caf8b7a..e3ae0fe 100755 (executable)
@@ -1033,9 +1033,11 @@ class GeneralUtility
      *
      * @param string $str Input string
      * @return string Uppercase String
+     * @deprecated since TYPO3 CMS v8, this method will be removed in TYPO3 CMS v9, Use \TYPO3\CMS\Core\Charset\CharsetConverter->conv_case() instead
      */
     public static function strtoupper($str)
     {
+        self::logDeprecatedFunction();
         return strtr((string)$str, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
     }
 
@@ -1047,9 +1049,11 @@ class GeneralUtility
      *
      * @param string $str Input string
      * @return string Lowercase String
+     * @deprecated since TYPO3 CMS v8, this method will be removed in TYPO3 CMS v9, Use \TYPO3\CMS\Core\Charset\CharsetConverter->conv_case() instead
      */
     public static function strtolower($str)
     {
+        self::logDeprecatedFunction();
         return strtr((string)$str, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
     }
 
@@ -1131,7 +1135,9 @@ class GeneralUtility
      */
     public static function camelCaseToLowerCaseUnderscored($string)
     {
-        return self::strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $string));
+        $charsetConverter = self::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
+        $value = preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $string);
+        return $charsetConverter->conv_case('utf-8', $value, 'toLower');
     }
 
     /**
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-76804-DeprecateGeneralUtilitystrtoupperStrtolower.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-76804-DeprecateGeneralUtilitystrtoupperStrtolower.rst
new file mode 100644 (file)
index 0000000..ce9b83d
--- /dev/null
@@ -0,0 +1,44 @@
+=======================================================================
+Deprecation: #76804 - Deprecate GeneralUtility::strtoupper & strtolower
+=======================================================================
+
+Description
+===========
+
+The following methods within ``GeneralUtility`` have been marked as deprecated:
+
+* strtoupper
+* strtolower
+
+
+Impact
+======
+
+Calling any of the methods above will trigger a deprecation log entry.
+
+
+Affected Installations
+======================
+
+Any installation with a 3rd party extension calling one of the methods in its PHP code.
+
+
+Migration
+=========
+
+Instead of :php:``GeneralUtility::strtoupper($value)`` use:
+
+.. code-block:: php
+
+    $charsetConverter = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
+    $charsetConverter->conv_case('utf-8', $value, 'toUpper');
+
+Instead of :php:``GeneralUtility::strtolower($value)`` use:
+
+.. code-block:: php
+
+    $charsetConverter = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
+    $charsetConverter->conv_case('utf-8', $value, 'toLower');
+
+Alternatively use the native implementation of :php:``strtoupper($value)`` or :php:``strtolower($value)``
+if the handled string consists of ascii characters only and has no multi byte characters like umlauts.
\ No newline at end of file
index 0c62bcb..e61e2d7 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Dbal\Database\SqlCompilers;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Dbal\Database\Specifics;
 use TYPO3\CMS\Dbal\Database\SqlParser;
@@ -505,10 +506,11 @@ class Adodb extends AbstractCompiler
                                         $output .= '(instr(' . trim((($v['table'] ? $v['table'] . '.' : '') . $v['field'])) . ', ' . $compareValue . ',1,1) > 0)';
                                     }
                                 } else {
+                                    $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
                                     if ($isLob) {
-                                        $output .= '(dbms_lob.instr(LOWER(' . trim(($v['table'] ? $v['table'] . '.' : '') . $v['field']) . '), ' . GeneralUtility::strtolower($compareValue) . ',1,1) > 0)';
+                                        $output .= '(dbms_lob.instr(LOWER(' . trim(($v['table'] ? $v['table'] . '.' : '') . $v['field']) . '), ' . $charsetConverter->conv_case('utf-8', $compareValue, 'toLower') . ',1,1) > 0)';
                                     } else {
-                                        $output .= '(instr(LOWER(' . trim(($v['table'] ? $v['table'] . '.' : '') . $v['field']) . '), ' . GeneralUtility::strtolower($compareValue) . ',1,1) > 0)';
+                                        $output .= '(instr(LOWER(' . trim(($v['table'] ? $v['table'] . '.' : '') . $v['field']) . '), ' . $charsetConverter->conv_case('utf-8', $compareValue, 'toLower') . ',1,1) > 0)';
                                     }
                                 }
                                 break;
index ec88583..bc1f3c6 100644 (file)
@@ -60,7 +60,7 @@ class TerUtility
         ) {
             throw new ExtensionManagerException('Extension Manager is in offline mode. No TER connection available.', 1437078620);
         }
-        $extensionPath = \TYPO3\CMS\Core\Utility\GeneralUtility::strtolower($extensionKey);
+        $extensionPath = strtolower($extensionKey);
         $mirrorUrl .= $extensionPath[0] . '/' . $extensionPath[1] . '/' . $extensionPath . '_' . $version . '.t3x';
         $t3x = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($mirrorUrl);
         $md5 = md5($t3x);
index 04f5bed..a4ad5db 100644 (file)
@@ -981,7 +981,7 @@ class FrontendLoginController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
         if ($this->frontendController->fe_user->user) {
             // All fields of fe_user will be replaced, scheme is ###FEUSER_FIELDNAME###
             foreach ($this->frontendController->fe_user->user as $field => $value) {
-                $marker['###FEUSER_' . GeneralUtility::strtoupper($field) . '###'] = $this->cObj->stdWrap($value, $this->conf['userfields.'][$field . '.']);
+                $marker['###FEUSER_' . strtoupper($field) . '###'] = $this->cObj->stdWrap($value, $this->conf['userfields.'][$field . '.']);
             }
             // Add ###USER### for compatibility
             $marker['###USER###'] = $marker['###FEUSER_USERNAME###'];
index 3b90d97..3275396 100644 (file)
@@ -38,7 +38,7 @@ class TerService extends TerUtility implements SingletonInterface
     public function fetchTranslationStatus($extensionKey, $mirrorUrl)
     {
         $result = false;
-        $extPath = GeneralUtility::strtolower($extensionKey);
+        $extPath = strtolower($extensionKey);
         $mirrorUrl .= $extPath[0] . '/' . $extPath[1] . '/' . $extPath . '-l10n/' . $extPath . '-l10n.xml';
         $remote = GeneralUtility::getUrl($mirrorUrl);
         if ($remote !== false) {
@@ -170,7 +170,7 @@ class TerService extends TerUtility implements SingletonInterface
      */
     protected function fetchTranslation($extensionKey, $language, $mirrorUrl)
     {
-        $extensionPath = GeneralUtility::strtolower($extensionKey);
+        $extensionPath = strtolower($extensionKey);
         // Typical non sysext path, Hungarian:
         // http://my.mirror/ter/a/n/anextension-l10n/anextension-l10n-hu.zip
         $packageUrl = $extensionPath[0] . '/' . $extensionPath[1] . '/' . $extensionPath .
index 8022346..fad9723 100644 (file)
@@ -113,19 +113,19 @@ class BlockElements extends RteHtmlAreaApi
             if (is_array($this->configuration['thisConfig']['buttons.']) && is_array($this->configuration['thisConfig']['buttons.']['formatblock.'])) {
                 // Removing elements
                 if ($this->configuration['thisConfig']['buttons.']['formatblock.']['removeItems']) {
-                    $hideItems = GeneralUtility::trimExplode(',', $this->cleanList(GeneralUtility::strtolower($this->configuration['thisConfig']['buttons.']['formatblock.']['removeItems'])), true);
+                    $hideItems = GeneralUtility::trimExplode(',', $this->cleanList(strtolower($this->configuration['thisConfig']['buttons.']['formatblock.']['removeItems'])), true);
                 }
                 // Adding elements
                 if ($this->configuration['thisConfig']['buttons.']['formatblock.']['addItems']) {
-                    $addItems = GeneralUtility::trimExplode(',', $this->cleanList(GeneralUtility::strtolower($this->configuration['thisConfig']['buttons.']['formatblock.']['addItems'])), true);
+                    $addItems = GeneralUtility::trimExplode(',', $this->cleanList(strtolower($this->configuration['thisConfig']['buttons.']['formatblock.']['addItems'])), true);
                 }
                 // Restriction clause
                 if ($this->configuration['thisConfig']['buttons.']['formatblock.']['restrictToItems']) {
-                    $restrictTo = GeneralUtility::trimExplode(',', $this->cleanList('none,' . GeneralUtility::strtolower($this->configuration['thisConfig']['buttons.']['formatblock.']['restrictToItems'])), true);
+                    $restrictTo = GeneralUtility::trimExplode(',', $this->cleanList('none,' . strtolower($this->configuration['thisConfig']['buttons.']['formatblock.']['restrictToItems'])), true);
                 }
                 // Elements order
                 if ($this->configuration['thisConfig']['buttons.']['formatblock.']['orderItems']) {
-                    $blockElementsOrder = 'none,' . GeneralUtility::strtolower($this->configuration['thisConfig']['buttons.']['formatblock.']['orderItems']);
+                    $blockElementsOrder = 'none,' . strtolower($this->configuration['thisConfig']['buttons.']['formatblock.']['orderItems']);
                 }
                 $prefixLabelWithTag = $this->configuration['thisConfig']['buttons.']['formatblock.']['prefixLabelWithTag'] ? true : $prefixLabelWithTag;
                 $postfixLabelWithTag = $this->configuration['thisConfig']['buttons.']['formatblock.']['postfixLabelWithTag'] ? true : $postfixLabelWithTag;
index 6d9bdef..c173217 100644 (file)
@@ -52,10 +52,10 @@ class ContextMenu extends RteHtmlAreaApi
         if (is_array($this->configuration['thisConfig']['contextMenu.'])) {
             $jsArray[] = 'RTEarea[editornumber].contextMenu =  ' . $this->buildNestedJSArray($this->configuration['thisConfig']['contextMenu.']) . ';';
             if ($this->configuration['thisConfig']['contextMenu.']['showButtons']) {
-                $jsArray[] = 'RTEarea[editornumber].contextMenu.showButtons = ' . json_encode(GeneralUtility::trimExplode(',', $this->cleanList(GeneralUtility::strtolower($this->configuration['thisConfig']['contextMenu.']['showButtons'])), true)) . ';';
+                $jsArray[] = 'RTEarea[editornumber].contextMenu.showButtons = ' . json_encode(GeneralUtility::trimExplode(',', $this->cleanList(strtolower($this->configuration['thisConfig']['contextMenu.']['showButtons'])), true)) . ';';
             }
             if ($this->configuration['thisConfig']['contextMenu.']['hideButtons']) {
-                $jsArray[] = 'RTEarea[editornumber].contextMenu.hideButtons = ' . json_encode(GeneralUtility::trimExplode(',', $this->cleanList(GeneralUtility::strtolower($this->configuration['thisConfig']['contextMenu.']['hideButtons'])), true)) . ';';
+                $jsArray[] = 'RTEarea[editornumber].contextMenu.hideButtons = ' . json_encode(GeneralUtility::trimExplode(',', $this->cleanList(strtolower($this->configuration['thisConfig']['contextMenu.']['hideButtons'])), true)) . ';';
             }
         }
         return implode(LF, $jsArray);