19 declare(strict_types=1);
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\".");
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);
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) {
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.