ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilCertificateUtilHelper.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 
32 {
33  private \ILIAS\Filesystem\Util\Convert\Images $image_converter;
34  private \ILIAS\Filesystem\Util\Archive\Archives $archives;
35  private \ILIAS\FileDelivery\Services $delivery;
36 
37  public function __construct()
38  {
39  global $DIC;
40  $this->image_converter = $DIC->fileConverters()->images();
41  $this->archives = $DIC->archives();
42  $this->delivery = $DIC->fileDelivery();
43  }
44 
45  public function deliverData(string $data, string $fileName, string $mimeType): void
46  {
48  $data,
49  $fileName,
50  $mimeType
51  );
52  }
53 
54  public function prepareFormOutput(string $string): string
55  {
57  }
58 
59  public function convertImage(
60  string $from,
61  string $to,
62  string $geometry = ''
63  ): void {
64  $converter = $this->image_converter->convertToFormat(
65  Streams::ofResource(fopen($from, 'rb')),
66  ImageOutputOptions::FORMAT_JPG,
67  $geometry === '' ? null : (int) $geometry,
68  $geometry === '' ? null : (int) $geometry,
69  (new ImageOutputOptions())->withQuality(100)
70  );
71 
72  if (!$converter->isOK()) {
73  throw new ilException(
74  sprintf(
75  'Could not convert image %s to %s',
76  $from,
77  $to
78  ),
79  0,
80  $converter->getThrowableIfAny()
81  );
82  }
83 
84  $stream = $converter->getStream();
85 
86  try {
87  $stream->rewind();
88  if (file_put_contents($to, $stream->getContents()) === false) {
89  throw new ilException(
90  sprintf(
91  'Could not store converted image %s to %s',
92  $from,
93  $to
94  )
95  );
96  }
97  } finally {
98  $stream->close();
99  }
100  }
101 
102  public function stripSlashes(string $string): string
103  {
104  return ilUtil::stripSlashes($string);
105  }
106 
110  public function zipAndDeliver(array $streams, string $download_filename): void
111  {
112  $this->delivery->delivery()->attached(
113  $this->archives->zip($streams)->get(),
114  $download_filename
115  );
116  }
117 
118  public function getDir(string $copyDirectory): array
119  {
120  return ilFileUtils::getDir($copyDirectory);
121  }
122 
123  public function unzip(string $file, string $zip_output_path, bool $overwrite): Unzip
124  {
125  return $this->archives->unzip(
126  Streams::ofResource(fopen($file, 'rb')),
127  $this->archives->unzipOptions()
128  ->withOverwrite($overwrite)
129  ->withZipOutputPath($zip_output_path)
130  ->withDirectoryHandling(ZipDirectoryHandling::KEEP_STRUCTURE)
131  );
132  }
133 
134  public function delDir(string $path): void
135  {
136  ilFileUtils::delDir($path);
137  }
138 
142  public function moveUploadedFile(
143  string $file,
144  string $name,
145  string $target,
146  bool $raise_errors = true,
147  string $mode = 'move_uploaded'
148  ): bool {
150  $file,
151  $name,
152  $target,
153  $raise_errors,
154  $mode
155  );
156  }
157 
158  public function getImagePath(
159  string $img,
160  string $module_path = "",
161  string $mode = "output",
162  bool $offline = false
163  ): string {
164  return ilUtil::getImagePath(
165  $img,
166  $module_path,
167  $mode,
168  $offline
169  );
170  }
171 }
convertImage(string $from, string $to, string $geometry='')
zipAndDeliver(array $streams, string $download_filename)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static deliverData(string $a_data, string $a_filename, string $mime="application/octet-stream")
static prepareFormOutput($a_str, bool $a_strip=false)
getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
$path
Definition: ltiservices.php:32
global $DIC
Definition: feed.php:28
moveUploadedFile(string $file, string $name, string $target, bool $raise_errors=true, string $mode='move_uploaded')
ILIAS FileDelivery Services $delivery
ILIAS Filesystem Util Convert Images $image_converter
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getDir(string $a_dir, bool $a_rec=false, ?string $a_sub_dir="")
get directory
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
deliverData(string $data, string $fileName, string $mimeType)
unzip(string $file, string $zip_output_path, bool $overwrite)
Just a wrapper class to create Unit Test for other classes.
ILIAS Filesystem Util Archive Archives $archives
getDir(string $copyDirectory)