ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Archives.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
32 final 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 
75  protected function mergeZipOptions(?ZipOptions $zip_options): ZipOptions
76  {
77  if (null === $zip_options) {
78  return $this->zip_options;
79  }
80  return $this->zip_options
81  ->withZipOutputName($zip_options->getZipOutputName())
82  ->withZipOutputPath($zip_options->getZipOutputPath())
83  ->withDirectoryHandling($zip_options->getDirectoryHandling());
84  }
85 
86  protected function mergeUnzipOptions(?UnzipOptions $unzip_options): UnzipOptions
87  {
88  if (null === $unzip_options) {
89  return $this->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 }
unzip(FileStream $zip, ?UnzipOptions $unzip_options=null)
Definition: Archives.php:57
zip(array $file_streams, ?ZipOptions $zip_options=null)
Definition: Archives.php:45
mergeZipOptions(?ZipOptions $zip_options)
Definition: Archives.php:75
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
withZipOutputPath(string $zip_output_path)
mergeUnzipOptions(?UnzipOptions $unzip_options)
Definition: Archives.php:86
withZipOutputName(string $zip_output_name)
Definition: ZipOptions.php:46
The base interface for all filesystem streams.
Definition: FileStream.php:31