feat: export data.json
This commit is contained in:
1 parent
d654bb8511
commit
a2324d2307
1 file changed
+24
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
final class JsonExporter
|
||||||
|
{
|
||||||
|
private PDO $pdo;
|
||||||
|
private string $filePath;
|
||||||
|
|
||||||
|
public function __construct(PDO $pdo, string $filePath)
|
||||||
|
{
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user