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); + } +}