chore: complete update
This commit is contained in:
71
src/Framework/Filesystem/File.php
Normal file
71
src/Framework/Filesystem/File.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Filesystem;
|
||||
|
||||
/**
|
||||
* Repräsentiert eine Datei im Dateisystem mit Lazy-Loading-Unterstützung.
|
||||
*
|
||||
* @property-read string $path Pfad zur Datei
|
||||
* @property-read Storage $storage Storage-Implementierung
|
||||
* @property-read string $contents Dateiinhalt (lazy geladen)
|
||||
* @property-read int $size Dateigröße in Bytes (lazy geladen)
|
||||
* @property-read int $lastModified Zeitstempel der letzten Änderung (lazy geladen)
|
||||
*/
|
||||
final readonly class File
|
||||
{
|
||||
public function __construct(
|
||||
public string $path,
|
||||
public Storage $storage,
|
||||
public string $contents = '',
|
||||
public int $size = 0,
|
||||
public int $lastModified = 0
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Prüft, ob die Datei existiert
|
||||
*/
|
||||
public function exists(): bool
|
||||
{
|
||||
return $this->storage->exists($this->path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht die Datei
|
||||
*/
|
||||
public function delete(): void
|
||||
{
|
||||
$this->storage->delete($this->path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kopiert die Datei an einen neuen Ort
|
||||
*/
|
||||
public function copyTo(string $destination): File
|
||||
{
|
||||
$this->storage->copy($this->path, $destination);
|
||||
return FilesystemFactory::createFile($destination, $this->storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt die Dateieigenschaften neu
|
||||
*/
|
||||
public function refresh(): File
|
||||
{
|
||||
return FilesystemFactory::createFile($this->path, $this->storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt erweiterte Metadaten der Datei
|
||||
*/
|
||||
public function getMetadata(): FileMetadata
|
||||
{
|
||||
return new FileMetadata(
|
||||
size: $this->size,
|
||||
lastModified: $this->lastModified,
|
||||
mimeType: $this->storage->getMimeType($this->path),
|
||||
isReadable: $this->storage->isReadable($this->path),
|
||||
isWritable: $this->storage->isWritable($this->path)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user