[TASK] Deprecate GeneralUtility::arrayToLogString() 56/57056/3
authorBenni Mack <benni@typo3.org>
Sun, 27 May 2018 13:13:38 +0000 (15:13 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Mon, 28 May 2018 11:34:12 +0000 (13:34 +0200)
The method arrayToLogString() within GeneralUtility is deprecated in favor of using
own implementations, based on PSR-3.

Still, the one place where this method was in use - ListSysLogCommand -
moved the logic into its own protected method.

Resolves: #85086
Releases: master
Change-Id: If6815a5ea9e459258408458b97b7ee4ad901bd40
Reviewed-on: https://review.typo3.org/57056
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-85086-GeneralUtilityArrayToLogString.rst [new file with mode: 0644]
typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php
typo3/sysext/lowlevel/Classes/Command/ListSysLogCommand.php

index adf099c..c57aa9f 100644 (file)
@@ -4022,9 +4022,11 @@ class GeneralUtility
      * @param mixed $valueList List of keys which should be listed in the output string. Pass a comma list or an array. An empty list outputs the whole array.
      * @param int $valueLength Long string values are shortened to this length. Default: 20
      * @return string Output string with key names and their value as string
+     * @deprecated since TYPO3 v9.3, will be removed in TYPO3 v10.
      */
     public static function arrayToLogString(array $arr, $valueList = [], $valueLength = 20)
     {
+        trigger_error('Method GeneralUtility::arrayToLogString() will be removed in TYPO3 v10. Use CLI-related methods in your code directly.', E_USER_DEPRECATED);
         $str = '';
         if (!is_array($valueList)) {
             $valueList = self::trimExplode(',', $valueList, true);
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85086-GeneralUtilityArrayToLogString.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85086-GeneralUtilityArrayToLogString.rst
new file mode 100644 (file)
index 0000000..02394d7
--- /dev/null
@@ -0,0 +1,37 @@
+.. include:: ../../Includes.txt
+
+========================================================
+Deprecation: #85086 - GeneralUtility::arrayToLogString()
+========================================================
+
+See :issue:`85086`
+
+Description
+===========
+
+The method :php:`GeneralUtility::arrayToLogString()`, responsible for formatting an array to a string
+ready for logging or output, has been marked as deprecated.
+
+
+Impact
+======
+
+Calling the method directly will trigger a deprecation warning.
+
+
+Affected Installations
+======================
+
+Any TYPO3 installation with third-party extensions using this method.
+
+
+Migration
+=========
+
+For logging purposes, switch to PSR-3 compatible logging where a log-writer is taking care of outputting / storing
+this information properly.
+
+For other purposes, like CLI-command output, it is recommended to implement this functionality directly in the
+corresponding CLI command.
+
+.. index:: CLI, PHP-API, FullyScanned, ext:core
\ No newline at end of file
index 70a6531..580413c 100644 (file)
@@ -547,32 +547,39 @@ return [
             'Deprecation-83475-AggregateValidatorInformationInClassSchema-2.rst',
         ],
     ],
-    'TYPO3\CMS\backend\Utility\BackendUtility::getPidForModTSconfig' => [
+    'TYPO3\CMS\Backend\Utility\BackendUtility::getPidForModTSconfig' => [
         'numberOfMandatoryArguments' => 3,
         'maximumNumberOfArguments' => 3,
         'restFiles' => [
             'Deprecation-84994-BackendUtilitygetPidForModTSconfigDeprecated.rst',
         ],
     ],
-    'TYPO3\CMS\backend\Utility\BackendUtility::getModTSconfig' => [
+    'TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig' => [
         'numberOfMandatoryArguments' => 2,
         'maximumNumberOfArguments' => 2,
         'restFiles' => [
             'Deprecation-84993-DeprecateSomeTSconfigRelatedMethods.rst',
         ],
     ],
-    'TYPO3\CMS\backend\Utility\BackendUtility::unsetMenuItems' => [
+    'TYPO3\CMS\Backend\Utility\BackendUtility::unsetMenuItems' => [
         'numberOfMandatoryArguments' => 3,
         'maximumNumberOfArguments' => 3,
         'restFiles' => [
             'Deprecation-84993-DeprecateSomeTSconfigRelatedMethods.rst',
         ],
     ],
-    'TYPO3\CMS\saltedpasswords\Utility\SaltedPasswordsUtility::isUsageEnabled' => [
+    'TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility::isUsageEnabled' => [
         'numberOfMandatoryArguments' => 0,
         'maximumNumberOfArguments' => 1,
         'restFiles' => [
             'Deprecation-85027-SaltedPasswordsRelatedMethodsAndClasses.rst',
         ],
     ],
+    'TYPO3\CMS\Core\Utility\GeneralUtility::arrayToLogString' => [
+        'numberOfMandatoryArguments' => 1,
+        'maximumNumberOfArguments' => 3,
+        'restFiles' => [
+            'Deprecation-85086-GeneralUtilityArrayToLogString.rst',
+        ],
+    ],
 ];
index 94708c9..c9db8a3 100644 (file)
@@ -92,7 +92,7 @@ class ListSysLogCommand extends Command
             ];
 
             if ($showDetails) {
-                $result[] = str_replace('; ', LF, GeneralUtility::arrayToLogString($row, [
+                $result[] = $this->arrayToLogString($row, [
                     'uid',
                     'userid',
                     'action',
@@ -107,10 +107,30 @@ class ListSysLogCommand extends Command
                     'event_pid',
                     'NEWid',
                     'workspace'
-                ]));
+                ]);
             }
             $content[] = $result;
         }
         $io->table($tableHeaders, $content);
     }
+
+    /**
+     * Converts a one dimensional array to a one line string which can be used for logging or debugging output
+     * Example: "loginType: FE; refInfo: Array; HTTP_HOST: www.example.org; REMOTE_ADDR: 192.168.1.5; REMOTE_HOST:; security_level:; showHiddenRecords: 0;"
+     * Previously found in GeneralUtility::arrayToLogString()
+     *
+     * @param array $arr Data array which should be outputted
+     * @param array $valueList List of keys which should be listed in the output string.
+     * @return string Output string with key names and their value as string
+     */
+    protected function arrayToLogString(array $arr, array $valueList): string
+    {
+        $str = '';
+        foreach ($arr as $key => $value) {
+            if (in_array($key, $valueList, true)) {
+                $str .= (string)$key . trim(': ' . GeneralUtility::fixed_lgd_cs(str_replace(LF, '|', (string)$value), 20)) . LF;
+            }
+        }
+        return $str;
+    }
 }