:". Example: "book:2") * which we can use to check uniqueness. * @var array */ protected array $validatedIds = []; public function __construct( public ZipExportReader $zipReader, ) { $this->validationFactory = app(Factory::class); } public function validateData(array $data, array $rules): array { $messages = $this->validationFactory->make($data, $rules)->errors()->messages(); foreach ($messages as $key => $message) { $messages[$key] = implode("\n", $message); } return $messages; } public function fileReferenceRule(): ZipFileReferenceRule { return new ZipFileReferenceRule($this); } public function uniqueIdRule(string $type): ZipUniqueIdRule { return new ZipUniqueIdRule($this, $type); } public function hasIdBeenUsed(string $type, int $id): bool { $key = $type . ':' . $id; if (isset($this->validatedIds[$key])) { return true; } $this->validatedIds[$key] = true; return false; } /** * Validate an array of relation data arrays that are expected * to be for the given ZipExportModel. * @param class-string $model */ public function validateRelations(array $relations, string $model): array { $results = []; foreach ($relations as $key => $relationData) { if (is_array($relationData)) { $results[$key] = $model::validate($this, $relationData); } else { $results[$key] = [trans('validation.zip_model_expected', ['type' => gettype($relationData)])]; } } return $results; } }