فهرست منبع

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 11 ماه پیش
والد
کامیت
9871a1f8fe
1فایلهای تغییر یافته به همراه18 افزوده شده و 0 حذف شده
  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);
+    }
+}