ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ZipAdapter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29
31{
34
35 public function __construct(
38 ) {
39 $this->archives = $archives;
40 $this->legacy_archives = $legacy_archives;
41 }
42
43 public function unzipFile(string $filepath): void
44 {
45 $unzip = $this->archives->unzip(
46 Streams::ofResource(fopen($filepath, 'rb')),
47 $this->archives->unzipOptions()
48 ->withZipOutputPath(dirname($filepath))
49 ->withOverwrite(false)
50 ->withDirectoryHandling(ZipDirectoryHandling::KEEP_STRUCTURE)
51 );
52 if (!$unzip->extract()) {
53 throw new ilException("Unzip failed.");
54 }
55 }
56
57 public function zipDirectoryToFile(string $directory, string $zip_file): void
58 {
59 $this->legacy_archives->zip(
60 $directory,
61 $zip_file,
62 true
63 );
64 }
65}
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
static ofResource($resource)
Wraps an already created resource with the stream abstraction.
Definition: Streams.php:64
zipDirectoryToFile(string $directory, string $zip_file)
Definition: ZipAdapter.php:57
__construct(Archives $archives, LegacyArchives $legacy_archives)
Definition: ZipAdapter.php:35