19declare(strict_types=1);
29use League\Flysystem\FilesystemException;
30use League\Flysystem\FilesystemOperator;
31use League\Flysystem\UnableToRetrieveMetadata;
32use League\Flysystem\UnableToDeleteFile;
33use League\Flysystem\UnableToWriteFile;
34use League\Flysystem\UnableToMoveFile;
35use League\Flysystem\UnableToCopyFile;
46 private FilesystemOperator $flysystem_operator
54 if (!$this->flysystem_operator->has(
$path)) {
55 throw new \League\Flysystem\FileNotFoundException(
$path);
57 $result = $this->flysystem_operator->read(
$path);
60 throw new IOException(
"Could not access the file \"$path\".");
64 }
catch (\Throwable $ex) {
71 return $this->flysystem_operator->has(
$path);
77 $mimeType = $this->flysystem_operator->mimeType(
$path);
78 if ($mimeType ===
'') {
79 throw new IOException(
"Could not determine the MIME type of the file \"$path\".");
83 }
catch (UnableToRetrieveMetadata $ex) {
91 $last_modified = (
int) $this->flysystem_operator->lastModified(
$path);
93 return new \DateTimeImmutable(date(
'Y-m-d H:i:s', $last_modified));
94 }
catch (UnableToRetrieveMetadata) {
95 throw new IOException(
"Could not lookup timestamp of the file \"$path\".");
96 }
catch (FilesystemException $ex) {
104 $byte_size = $this->flysystem_operator->fileSize(
$path);
105 return new DataSize($byte_size, $unit);
106 }
catch (UnableToRetrieveMetadata) {
120 if (!$this->
has($path)) {
127 $this->flysystem_operator->setVisibility(
$path, $visibility);
128 }
catch (\Throwable) {
150 throw new \InvalidArgumentException(
"The access must be 'public' or 'private' but '$visibility' was given.");
170 if (!$this->
has($path)) {
174 $visibility = $this->flysystem_operator->getVisibility(
$path);
176 if ($visibility ===
false) {
177 throw new IOException(
"Could not determine visibility for path '$path'.");
196 if ($this->flysystem_operator->has(
$path)) {
200 $this->flysystem_operator->write(
$path, $content);
201 }
catch (FilesystemException) {
203 "Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable."
223 $this->flysystem_operator->write(
$path, $new_content);
224 }
catch (UnableToWriteFile $ex) {
226 "Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable.",
230 }
catch (UnableToRetrieveMetadata $ex) {
245 public function put(
string $path,
string $content): void
247 if ($this->flysystem_operator->has(
$path)) {
248 $this->
update($path, $content);
251 $this->
write($path, $content);
264 public function delete(
string $path):
void
267 $this->flysystem_operator->delete(
$path);
268 }
catch (UnableToRetrieveMetadata) {
270 }
catch (UnableToDeleteFile) {
272 "Could not delete file \"$path\" because a general IO error occurred. Please check that your target is writable."
290 $content = $this->
read($path);
291 $this->
delete(
$path);
310 if ($this->flysystem_operator->has($new_path)) {
311 throw new IOException(
"File \"$new_path\" already exists.");
314 $this->flysystem_operator->move(
$path, $new_path);
315 }
catch (UnableToMoveFile) {
316 throw new IOException(
"Could not move file from \"$path\" to \"$new_path\".");
317 }
catch (UnableToRetrieveMetadata) {
333 public function copy(
string $path,
string $copy_path): void
335 if ($this->flysystem_operator->has($copy_path)) {
339 $this->flysystem_operator->copy(
$path, $copy_path);
340 }
catch (UnableToCopyFile) {
342 "Could not copy file \"$path\" to destination \"$copy_path\" because a general IO error occurred. Please check that your destination is writable."
344 }
catch (UnableToRetrieveMetadata) {
This class provides the data size with additional information to remove the work to calculate the siz...
Indicates that a file is missing or not found.
Indicates general problems with the input or output operations.
Fly system file access implementation.
getVisibility(string $path)
Get the file visibility.
setVisibility(string $path, string $visibility)
Sets the visibility for a file.
put(string $path, string $content)
Creates a file or updates an existing one.
copy(string $path, string $copy_path)
Copy the source file to a destination.
__construct(private FilesystemOperator $flysystem_operator)
update(string $path, string $new_content)
Updates the content of a file.
has(string $path)
Checks whether a file exists.
readAndDelete(string $path)
Reads the entire file content into a string and removes the file afterwards.
write(string $path, string $content)
Writes the content to a new file.
validateVisibility(string $visibility)
Checks if the given visibility is valid an throws an exception otherwise.
getSize(string $path, int $unit)
Get the size of a file.
getMimeType(string $path)
Get a files mime-type.
read(string $path)
Reads a file content to a string.
rename(string $path, string $new_path)
Moves a file from the source to the destination.
getTimestamp(string $path)
Get the timestamp of the file.
static normalizeRelativePath(string $path)
This interface provides the available options for the filesystem right management of the filesystem s...
const PRIVATE_ACCESS
Private file visibility.
const PUBLIC_ACCESS
Public file visibility.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...