ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Archives.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
32final class Archives
33{
34 use PathHelper;
35
38
39 public function __construct()
40 {
41 $this->zip_options = $this->zipOptions();
42 $this->unzip_options = $this->unzipOptions();
43 }
44
45 public function zip(array $file_streams, ?ZipOptions $zip_options = null): Zip
46 {
47 if (empty($file_streams)) {
48 $file_streams = [Zip::DOT_EMPTY => Streams::ofString('')];
49 }
50
51 return new Zip(
52 $this->mergeZipOptions($zip_options),
53 ...$file_streams
54 );
55 }
56
57 public function unzip(FileStream $zip, ?UnzipOptions $unzip_options = null): Unzip
58 {
59 return new Unzip(
60 $this->mergeUnzipOptions($unzip_options),
61 $zip
62 );
63 }
64
65 public function unzipOptions(): UnzipOptions
66 {
67 return new UnzipOptions();
68 }
69
70 public function zipOptions(): ZipOptions
71 {
72 return new ZipOptions();
73 }
74
76 {
77 if (null === $zip_options) {
78 return $this->zip_options;
79 }
80 return $this->zip_options
82 ->withZipOutputPath($zip_options->getZipOutputPath())
83 ->withDirectoryHandling($zip_options->getDirectoryHandling());
84 }
85
87 {
88 if (null === $unzip_options) {
90 }
91 if ($unzip_options->getZipOutputPath() !== null) {
92 $this->unzip_options = $this->unzip_options->withZipOutputPath($unzip_options->getZipOutputPath());
93 }
94
95 return $this->unzip_options
96 ->withOverwrite($unzip_options->isOverwrite())
97 ->withDirectoryHandling($unzip_options->getDirectoryHandling());
98 }
99}
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41
unzip(FileStream $zip, ?UnzipOptions $unzip_options=null)
Definition: Archives.php:57
zip(array $file_streams, ?ZipOptions $zip_options=null)
Definition: Archives.php:45
mergeUnzipOptions(?UnzipOptions $unzip_options)
Definition: Archives.php:86
mergeZipOptions(?ZipOptions $zip_options)
Definition: Archives.php:75
withZipOutputPath(string $zip_output_path)
withZipOutputName(string $zip_output_name)
Definition: ZipOptions.php:46
The base interface for all filesystem streams.
Definition: FileStream.php:32