BookStack/app/Exports/ZipExports/ZipValidationHelper.php

33 lines
730 B
PHP
Raw Normal View History

2024-10-30 21:13:41 +08:00
<?php
namespace BookStack\Exports\ZipExports;
use Illuminate\Validation\Factory;
use ZipArchive;
class ZipValidationHelper
{
protected Factory $validationFactory;
public function __construct(
protected ZipArchive $zip,
) {
$this->validationFactory = app(Factory::class);
}
public function validateArray(array $data, array $rules): array
{
return $this->validationFactory->make($data, $rules)->errors()->messages();
}
public function zipFileExists(string $name): bool
{
return $this->zip->statName("files/{$name}") !== false;
}
public function fileReferenceRule(): ZipFileReferenceRule
{
return new ZipFileReferenceRule($this);
}
}