Spatie\Backup\Tasks\Backup\Zip::createForManifest PHP Method

createForManifest() public static method

public static createForManifest ( Manifest $manifest, string $pathToZip ) : Zip
$manifest Manifest
$pathToZip string
return Zip
    public static function createForManifest(Manifest $manifest, string $pathToZip) : Zip
    {
        $zip = new static($pathToZip);
        $zip->open();
        foreach ($manifest->files() as $file) {
            $zip->add($file, self::determineNameOfFileInZip($file, $pathToZip));
        }
        $zip->close();
        return $zip;
    }

Usage Example

Example #1
0
 protected function createZipContainingEveryFileInManifest(Manifest $manifest)
 {
     consoleOutput()->info("Zipping {$manifest->count()} files...");
     $pathToZip = $this->temporaryDirectory->path(config('laravel-backup.backup.destination.filename_prefix') . Carbon::now()->format('Y-m-d-H-i-s') . '.zip');
     $zip = Zip::createForManifest($manifest, $pathToZip);
     consoleOutput()->info("Created zip containing {$zip->count()} files. Size is {$zip->humanReadableSize()}");
     event(new BackupZipWasCreated($pathToZip));
     return $pathToZip;
 }