浏览代码

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 月之前
父节点
当前提交
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);
+    }
+}