]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/Utils.php
Dislay an error if an exception occurs in the error handler
[github/shaarli/Shaarli.git] / application / Utils.php
index 72c90049b9b41c3e7926bede39c4caf6facc2a6a..37be9a13fdf89df0e9eeadc03c4b8c0a10f7c043 100644 (file)
@@ -91,14 +91,18 @@ function endsWith($haystack, $needle, $case = true)
  */
 function escape($input)
 {
-    if (is_bool($input)) {
+    if (null === $input) {
+        return null;
+    }
+
+    if (is_bool($input) || is_int($input) || is_float($input) || $input instanceof DateTimeInterface) {
         return $input;
     }
 
     if (is_array($input)) {
         $out = array();
         foreach ($input as $key => $value) {
-            $out[$key] = escape($value);
+            $out[escape($key)] = escape($value);
         }
         return $out;
     }
@@ -459,3 +463,12 @@ function t($text, $nText = '', $nb = 1, $domain = 'shaarli')
 {
     return dn__($domain, $text, $nText, $nb);
 }
+
+/**
+ * Converts an exception into a printable stack trace string.
+ */
+function exception2text(Throwable $e): string
+{
+    return $e->getMessage() . PHP_EOL . $e->getFile() . $e->getLine() . PHP_EOL . $e->getTraceAsString();
+}
+