2declare(strict_types=1);
14use League\Flysystem\FilesystemInterface;
15use League\Flysystem\RootViolationException;
57 public function hasDir(
string $path) : bool
59 if ($this->flySystemFS->has($path)) {
60 $meta = $this->flySystemFS->getMetadata($path);
62 if (!(is_array($meta) && array_key_exists(self::$metaTypeKey, $meta))) {
63 throw new IOException(
"Could not evaluate path type: \"$path\"");
82 public function listContents(
string $path =
'',
bool $recursive =
false) : array
88 $contents = $this->flySystemFS->listContents($path, $recursive);
89 $metadataCollection = [];
91 foreach ($contents as $content) {
92 if (!(array_key_exists(self::$metaTypeKey, $content) && array_key_exists(self::$metaPathKey, $content))) {
93 throw new IOException(
"Invalid metadata received for path \"$path\"");
99 return $metadataCollection;
118 $config = [
'visibility' => $visibility];
119 $successful = $this->flySystemFS->createDir($path,
$config);
122 throw new IOException(
"Could not create directory \"$path\"");
147 foreach ($contentList as $content) {
150 if ($content->isFile()) {
153 $position = strpos($content->getPath(),
$source);
154 if ($position !==
false) {
155 $destinationFilePath = substr_replace($content->getPath(), $destination, $position,
157 $this->fileAccess->copy($content->getPath(), $destinationFilePath);
174 if (count($destinationContent) !== 0) {
175 throw new IOException(
"Destination \"$path\" is not empty can not copy files.");
190 if (!$this->
hasDir($path)) {
206 if ($this->flySystemFS->deleteDir($path) ===
false) {
207 throw new IOException(
"Could not delete directory \"$path\".");
209 }
catch (RootViolationException $ex) {
210 throw new IOException(
'The filesystem root must not be deleted.', 0, $ex);
227 $metadataArray[self::$metaPathKey],
228 $metadataArray[self::$metaTypeKey]
242 throw new \InvalidArgumentException(
"Invalid visibility expected public or private but got \"$visibility\".");
An exception for terminatinating execution or to throw for unit testing.
Class DirectoryNotFoundException Indicates that the directory is missing or not found.
Class IOException Indicates general problems with the input or output operations.
Class FlySystemDirectoryAccess.
createDir(string $path, string $visibility=Visibility::PUBLIC_ACCESS)
Create a new directory.
deleteDir(string $path)
Deletes a directory recursive.
copyDir(string $source, string $destination)
Copy all childes of the source recursive to the destination.
listContents(string $path='', bool $recursive=false)
Lists the content of a directory.
hasDir(string $path)
Checks whether the directory exists or not.
__construct(FilesystemInterface $flySystemFS, FlySystemFileAccess $fileAccess)
FlySystemDirectoryAccess constructor.
validateVisibility($visibility)
Validates if the given visibility is known, otherwise an exception is thrown.
ensureEmptyDirectory(string $path)
Ensures that the given path does not exist or is empty.
ensureDirectoryExistence(string $path)
Checks if the directory exists.
arrayToMetadata(array $metadataArray)
Parses a metadata array into a metadata object.
Class FlySystemFileAccess Fly system file access implementation.
Interface DirectoryAccess Defines all directory access operations of the filesystem.
Interface Visibility This interface provides the available options for the filesystem right managemen...
const PRIVATE_ACCESS
Private file visibility.
const PUBLIC_ACCESS
Public file visibility.