]> BookStack Code Mirror - bookstack/blobdiff - app/Exports/ZipExportModels/ZipExportModel.php
Zip Exports: Added attachment/image link resolving & JSON null handling
[bookstack] / app / Exports / ZipExportModels / ZipExportModel.php
index e1cb616de5247a1ed0f3b68263c6e35115aac652..26b994c018ef7e37e3f8f1bc7e0edc22c6b794a0 100644 (file)
@@ -2,10 +2,19 @@
 
 namespace BookStack\Exports\ZipExportModels;
 
-use BookStack\App\Model;
-use BookStack\Exports\ZipExportFiles;
+use JsonSerializable;
 
-interface ZipExportModel
+abstract class ZipExportModel implements JsonSerializable
 {
-//    public static function fromModel(Model $model, ZipExportFiles $files): self;
+    /**
+     * Handle the serialization to JSON.
+     * For these exports, we filter out optional (represented as nullable) fields
+     * just to clean things up and prevent confusion to avoid null states in the
+     * resulting export format itself.
+     */
+    public function jsonSerialize(): array
+    {
+        $publicProps = get_object_vars(...)->__invoke($this);
+        return array_filter($publicProps, fn ($value) => $value !== null);
+    }
 }