3 declare(strict_types=1);
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);
182 $byteSize = $this->flySystemFS->
getSize($path);
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) {
Class FileAlreadyExistsException.
put(string $path, string $content)
Creates a file or updates an existing one.
validateVisibility(string $visibility)
Checks if the given visibility is valid an throws an exception otherwise.
This class provides the data size with additional information to remove the work to calculate the siz...
Class FlySystemFileAccess.
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.
getSize(string $path, int $fileSizeUnit)
Get the size of a file.
getVisibility(string $path)
Get the file visibility.
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.
getSize()
The calculated data size.
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.
Class FileNotFoundException.
FilesystemInterface $flySystemFS
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 (mtime) of the file.
__construct(FilesystemInterface $flySystemFS)
FlySystemFileAccess constructor.
static normalizeRelativePath($path)
getMimeType(string $path)
Get a files mime-type.