2024-10-21 02:56:56 +08:00
|
|
|
<?php
|
|
|
|
|
2024-10-23 17:48:26 +08:00
|
|
|
namespace BookStack\Exports\ZipExports\Models;
|
2024-10-21 02:56:56 +08:00
|
|
|
|
2024-10-30 21:13:41 +08:00
|
|
|
use BookStack\Exports\ZipExports\ZipValidationHelper;
|
2024-10-21 19:13:41 +08:00
|
|
|
use JsonSerializable;
|
2024-10-21 02:56:56 +08:00
|
|
|
|
2024-10-21 19:13:41 +08:00
|
|
|
abstract class ZipExportModel implements JsonSerializable
|
2024-10-21 02:56:56 +08:00
|
|
|
{
|
2024-10-21 19:13:41 +08:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
2024-10-30 21:13:41 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate the given array of data intended for this model.
|
|
|
|
* Return an array of validation errors messages.
|
|
|
|
* Child items can be considered in the validation result by returning a keyed
|
|
|
|
* item in the array for its own validation messages.
|
|
|
|
*/
|
|
|
|
abstract public static function validate(ZipValidationHelper $context, array $data): array;
|
2024-10-21 02:56:56 +08:00
|
|
|
}
|