19 declare(strict_types=1);
48 private FilesystemOperator $flysystem_operator
56 if (!$this->flysystem_operator->has($path)) {
57 throw new \League\Flysystem\FileNotFoundException($path);
59 $result = $this->flysystem_operator->read($path);
62 throw new IOException(
"Could not access the file \"$path\".");
73 return $this->flysystem_operator->has($path);
79 $mimeType = $this->flysystem_operator->mimeType($path);
80 if ($mimeType ===
'') {
81 throw new IOException(
"Could not determine the MIME type of the file \"$path\".");
85 }
catch (UnableToRetrieveMetadata $ex) {
93 $last_modified = (
int) $this->flysystem_operator->lastModified($path);
95 return new \DateTimeImmutable(date(
'Y-m-d H:i:s', $last_modified));
96 }
catch (UnableToRetrieveMetadata $ex) {
97 throw new IOException(
"Could not lookup timestamp of the file \"$path\".");
98 }
catch (FilesystemException $ex) {
106 $byte_size = $this->flysystem_operator->fileSize($path);
107 return new DataSize($byte_size, $unit);
108 }
catch (UnableToRetrieveMetadata) {
122 if (!$this->
has($path)) {
129 $this->flysystem_operator->setVisibility($path, $visibility);
152 throw new \InvalidArgumentException(
"The access must be 'public' or 'private' but '$visibility' was given.");
172 if (!$this->
has($path)) {
176 $visibility = $this->flysystem_operator->getVisibility($path);
178 if ($visibility ===
false) {
179 throw new IOException(
"Could not determine visibility for path '$path'.");
198 if ($this->flysystem_operator->has($path)) {
202 $this->flysystem_operator->write($path, $content);
203 }
catch (FilesystemException) {
205 "Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable." 225 $this->flysystem_operator->write($path, $new_content);
226 }
catch (UnableToWriteFile $ex) {
228 "Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable.",
232 }
catch (UnableToRetrieveMetadata $ex) {
247 public function put(
string $path,
string $content): void
249 if ($this->flysystem_operator->has($path)) {
250 $this->
update($path, $content);
253 $this->
write($path, $content);
266 public function delete(
string $path):
void 269 $this->flysystem_operator->delete(
$path);
270 }
catch (UnableToRetrieveMetadata) {
272 }
catch (UnableToDeleteFile) {
274 "Could not delete file \"$path\" because a general IO error occurred. Please check that your target is writable." 292 $content = $this->
read($path);
293 $this->
delete(
$path);
312 if ($this->flysystem_operator->has($new_path)) {
313 throw new IOException(
"File \"$new_path\" already exists.");
316 $this->flysystem_operator->move($path, $new_path);
317 }
catch (UnableToMoveFile) {
318 throw new IOException(
"Could not move file from \"$path\" to \"$new_path\".");
319 }
catch (UnableToRetrieveMetadata) {
335 public function copy(
string $path,
string $copy_path): void
337 if ($this->flysystem_operator->has($copy_path)) {
341 $this->flysystem_operator->copy($path, $copy_path);
342 }
catch (UnableToCopyFile) {
344 "Could not copy file \"$path\" to destination \"$copy_path\" because a general IO error occurred. Please check that your destination is writable." 346 }
catch (UnableToRetrieveMetadata) {
put(string $path, string $content)
Creates a file or updates an existing one.
Indicates general problems with the input or output operations.
validateVisibility(string $visibility)
Checks if the given visibility is valid an throws an exception otherwise.
static normalizeRelativePath(string $path)
This class provides the data size with additional information to remove the work to calculate the siz...
Fly system file access implementation.
read(string $path)
Reads a file content to a string.
readAndDelete(string $path)
Reads the entire file content into a string and removes the file afterwards.
getVisibility(string $path)
Get the file visibility.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(private FilesystemOperator $flysystem_operator)
const PRIVATE_ACCESS
Private file visibility.
setVisibility(string $path, string $visibility)
Sets the visibility for a file.
update(string $path, string $new_content)
Updates the content of a file.
rename(string $path, string $new_path)
Moves a file from the source to the destination.
copy(string $path, string $copy_path)
Copy the source file to a destination.
Indicates that a file is missing or not found.
getSize(string $path, int $unit)
Get the size of a file.
has(string $path)
Checks whether a file exists.
write(string $path, string $content)
Writes the content to a new file.
const PUBLIC_ACCESS
Public file visibility.
getTimestamp(string $path)
Get the timestamp of the file.
getMimeType(string $path)
Get a files mime-type.