3declare(strict_types=1);
13use League\Flysystem\FileExistsException;
14use League\Flysystem\FilesystemInterface;
71 $adapter = $this->flySystemFS->getAdapter();
72 if (!$adapter->has(
$path)) {
73 throw new \League\Flysystem\FileNotFoundException(
$path);
75 $object = $adapter->read(
$path);
76 $result = $object[
'contents'];
78 if ($result ===
false) {
79 throw new IOException(
"Could not access the file \"$path\".");
101 return $this->flySystemFS->has(
$path);
118 $mimeType = $this->flySystemFS->getMimetype(
$path);
119 if ($mimeType ===
false) {
120 throw new IOException(
"Could not determine the MIME type of the file \"$path\".");
146 $rawTimestamp = $this->flySystemFS->getTimestamp(
$path);
147 if ($rawTimestamp ===
false) {
148 throw new IOException(
"Could not lookup timestamp of the file \"$path\".");
151 if (is_numeric($rawTimestamp)) {
152 $rawTimestamp =
'@' . $rawTimestamp;
155 return new \DateTimeImmutable($rawTimestamp);
185 if ($byteSize ===
false) {
186 throw new IOException(
"Could not calculate the file size of the file \"$path\".");
189 $size =
new DataSize($byteSize, $fileSizeUnit);
216 if ($this->
has($path) ===
false) {
222 return $this->flySystemFS->setVisibility(
$path, $visibility);
237 throw new \InvalidArgumentException(
"The access must be 'public' or 'private' but '$visibility' was given.");
261 if ($this->
has($path) ===
false) {
265 $visibility = $this->flySystemFS->getVisibility(
$path);
267 if ($visibility ===
false) {
268 throw new IOException(
"Could not determine visibility for path '$path'.");
291 if ($this->flySystemFS->write(
$path, $content) ===
false) {
292 throw new IOException(
"Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable.");
294 }
catch (FileExistsException $ex) {
317 if ($this->flySystemFS->update(
$path, $new_content) ===
false) {
318 throw new IOException(
"Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable.");
338 public function put(
string $path,
string $content): void
340 if ($this->flySystemFS->put(
$path, $content) ===
false) {
341 throw new IOException(
"Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable.");
358 public function delete(
string $path):
void
361 if ($this->flySystemFS->delete(
$path) ===
false) {
362 throw new IOException(
"Could not delete file \"$path\" because a general IO error occurred. Please check that your target is writable.");
385 $content = $this->
read($path);
386 $this->
delete(
$path);
409 if ($this->flySystemFS->rename(
$path, $new_path) ===
false) {
410 throw new IOException(
"Could not move file from \"$path\" to \"$new_path\".");
412 }
catch (FileExistsException $ex) {
434 public function copy(
string $path,
string $copy_path): void
437 if ($this->flySystemFS->copy(
$path, $copy_path) ===
false) {
438 throw new IOException(
"Could not copy file \"$path\" to destination \"$copy_path\" because a general IO error occurred. Please check that your destination is writable.");
440 }
catch (FileExistsException $ex) {
This class provides the data size with additional information to remove the work to calculate the siz...
getSize()
The calculated data size.
Class FileAlreadyExistsException.
Class FileNotFoundException.
Class FlySystemFileAccess.
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.
FilesystemInterface $flySystemFS
copy(string $path, string $copy_path)
Copy the source file to a destination.
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.
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.
__construct(FilesystemInterface $flySystemFS)
FlySystemFileAccess constructor.
getTimestamp(string $path)
Get the timestamp (mtime) of the file.
getSize(string $path, int $fileSizeUnit)
Get the size of a file.
static normalizeRelativePath($path)
const PRIVATE_ACCESS
Private file visibility.
const PUBLIC_ACCESS
Public file visibility.