19declare(strict_types=1);
28use League\Flysystem\CorruptedPathDetected;
29use League\Flysystem\FilesystemOperator;
30use League\Flysystem\UnableToRetrieveMetadata;
31use League\Flysystem\UnableToCreateDirectory;
32use League\Flysystem\StorageAttributes;
50 private FilesystemOperator $flysystem_operator,
55 public function hasDir(
string $path): bool
58 return $this->flysystem_operator->directoryExists($path);
59 }
catch (CorruptedPathDetected) {
70 public function listContents(
string $path =
'',
bool $recursive =
false): array
79 $contents = $this->flysystem_operator->listContents($path, $recursive);
80 $metadata_collection = [];
86 return $metadata_collection;
97 $config = [
'visibility' => $visibility];
99 $this->flysystem_operator->createDirectory($path, $config);
100 }
catch (UnableToCreateDirectory) {
101 throw new IOException(
"Could not create directory \"$path\"");
112 public function copyDir(
string $source,
string $destination): void
120 foreach ($content_list as $content) {
122 if ($content->isFile()) {
124 $position = strpos($content->getPath(), $source);
125 if ($position !==
false) {
126 $destinationFilePath = substr_replace(
132 $this->flysystem_access->copy($content->getPath(), $destinationFilePath);
145 $destination_content = $this->
listContents($path,
true);
146 if ($destination_content !== []) {
147 throw new IOException(
"Destination \"$path\" is not empty can not copy files.");
149 }
catch (UnableToRetrieveMetadata) {
160 if (!$this->
hasDir($path)) {
168 $this->flysystem_operator->deleteDirectory($path);
169 }
catch (UnableToRetrieveMetadata) {
170 throw new IOException(
"Could not find directory \"$path\".");
171 }
catch (UnableToDeleteDirectory|\Throwable) {
172 throw new IOException(
"Could not delete directory \"$path\".");
174 if ($this->flysystem_operator->has($path)) {
175 throw new IOException(
"Could not find directory \"$path\".");
199 throw new \InvalidArgumentException(
"Invalid visibility expected public or private but got \"$visibility\".");
Indicates that the directory is missing or not found.
Indicates general problems with the input or output operations.
createDir(string $path, string $visibility=Visibility::PUBLIC_ACCESS)
Please note that the Visibility interface defines two constants PUBLIC_ACCESS and PRIVATE_ACCESS to e...
__construct(private FilesystemOperator $flysystem_operator, private FlySystemFileAccess $flysystem_access)
deleteDir(string $path)
Deletes a directory recursive.
attributesToMetadata(StorageAttributes $attributes)
copyDir(string $source, string $destination)
Copy all childes of the source recursive to the destination.
hasDir(string $path)
Checks whether the directory exists or not.
ensureEmptyDirectory(string $path)
Ensures that the given path does not exist or is empty.
ensureDirectoryExistence(string $path)
Checks if the directory exists.
validateVisibility(string $visibility)
Validates if the given visibility is known, otherwise an exception is thrown.
Fly system file access implementation.
listContents(string $path='', bool $recursive=false)
Lists the content of a directory.
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...