Bladeren bron

Adds debug utility for dumping variables to file

Introduces a debug utility that allows developers to easily dump variables to a file for inspection.

This facilitates debugging by providing a simple way to persist variable states for later analysis, especially useful in environments where standard debugging tools are limited.
Olivier Massot 5 maanden geleden
bovenliggende
commit
9871a1f8fe
1 gewijzigde bestanden met toevoegingen van 18 en 0 verwijderingen
  1. 18 0
      src/Service/Utils/DebugUtils.php

+ 18 - 0
src/Service/Utils/DebugUtils.php

@@ -0,0 +1,18 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Service\Utils;
+
+use Path\Path;
+
+class DebugUtils
+{
+    public static function dumpToFile(mixed $var, bool $append = false): void {
+        $debugFile = (new Path(PathUtils::getProjectDir()))->append('var', 'dump.log');
+
+        $datetime = date('Y-m-d H:i:s');
+        $content = json_encode($var, JSON_PRETTY_PRINT);
+
+        $debugFile->putContent("$datetime - $content\n", $append);
+    }
+}