]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Logger/AbstractLogger.php
Merge branch '2021.03-rc' into copyright-2021
[friendica.git] / src / Util / Logger / AbstractLogger.php
index 3fab1b88ded8659cdaff009981db690e02ae94f4..bbd50d619ebda7bbe086db8cec3997c27eb08256 100644 (file)
@@ -103,6 +103,28 @@ abstract class AbstractLogger implements LoggerInterface
                return strtr($message, $replace);
        }
 
+       /**
+        * JSON Encodes an complete array including objects with "__toString()" methods
+        *
+        * @param array $input an Input Array to encode
+        *
+        * @return false|string The json encoded output of the array
+        */
+       protected function jsonEncodeArray(array $input)
+       {
+               $output = [];
+
+               foreach ($input as $key => $value) {
+                       if (method_exists($value, '__toString')) {
+                               $output[$key] = $value->__toString();
+                       } else {
+                               $output[$key] = $value;
+                       }
+               }
+
+               return @json_encode($output);
+       }
+
        /**
         * {@inheritdoc}
         */