From a2324d230776ec5a2a2a5fabcc2f32e4890e67f3 Mon Sep 17 00:00:00 2001 From: gilles Date: Mon, 14 Sep 2026 14:33:18 +0200 Subject: [PATCH] feat: export data.json --- src/JsonExporter.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/JsonExporter.php diff --git a/src/JsonExporter.php b/src/JsonExporter.php new file mode 100644 index 0000000..04b536c --- /dev/null +++ b/src/JsonExporter.php @@ -0,0 +1,24 @@ +pdo = $pdo; + $this->filePath = $filePath; + } + + public function export(): void + { + $links = $this->pdo->query('SELECT * FROM links ORDER BY id DESC')->fetchAll(); + + $json = json_encode($links, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + + file_put_contents($this->filePath, $json . PHP_EOL, LOCK_EX); + } +}