| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace League\Flysystem; |
| 6 |
|
| 7 |
class FileAttributes implements StorageAttributes |
| 8 |
{ |
| 9 |
use ProxyArrayAccessToProperties; |
| 10 |
private string $type = StorageAttributes::TYPE_FILE; |
| 11 |
|
| 12 |
public function __construct( |
| 13 |
private string $path, |
| 14 |
private ?int $fileSize = null, |
| 15 |
private ?string $visibility = null, |
| 16 |
private ?int $lastModified = null, |
| 17 |
private ?string $mimeType = null, |
| 18 |
private array $extraMetadata = [] |
| 19 |
) { |
| 20 |
$this->path = ltrim($this->path, '/'); |
| 21 |
} |
| 22 |
|
| 23 |
public function type(): string |
| 24 |
{ |
| 25 |
return $this->type; |
| 26 |
} |
| 27 |
|
| 28 |
public function path(): string |
| 29 |
{ |
| 30 |
return $this->path; |
| 31 |
} |
| 32 |
|
| 33 |
public function fileSize(): ?int |
| 34 |
{ |
| 35 |
return $this->fileSize; |
| 36 |
} |
| 37 |
|
| 38 |
public function visibility(): ?string |
| 39 |
{ |
| 40 |
return $this->visibility; |
| 41 |
} |
| 42 |
|
| 43 |
public function lastModified(): ?int |
| 44 |
{ |
| 45 |
return $this->lastModified; |
| 46 |
} |
| 47 |
|
| 48 |
public function mimeType(): ?string |
| 49 |
{ |
| 50 |
return $this->mimeType; |
| 51 |
} |
| 52 |
|
| 53 |
public function extraMetadata(): array |
| 54 |
{ |
| 55 |
return $this->extraMetadata; |
| 56 |
} |
| 57 |
|
| 58 |
public function isFile(): bool |
| 59 |
{ |
| 60 |
return true; |
| 61 |
} |
| 62 |
|
| 63 |
public function isDir(): bool |
| 64 |
{ |
| 65 |
return false; |
| 66 |
} |
| 67 |
|
| 68 |
public function withPath(string $path): self |
| 69 |
{ |
| 70 |
$clone = clone $this; |
| 71 |
$clone->path = $path; |
| 72 |
|
| 73 |
return $clone; |
| 74 |
} |
| 75 |
|
| 76 |
public static function fromArray(array $attributes): self |
| 77 |
{ |
| 78 |
return new FileAttributes( |
| 79 |
$attributes[StorageAttributes::ATTRIBUTE_PATH], |
| 80 |
$attributes[StorageAttributes::ATTRIBUTE_FILE_SIZE] ?? null, |
| 81 |
$attributes[StorageAttributes::ATTRIBUTE_VISIBILITY] ?? null, |
| 82 |
$attributes[StorageAttributes::ATTRIBUTE_LAST_MODIFIED] ?? null, |
| 83 |
$attributes[StorageAttributes::ATTRIBUTE_MIME_TYPE] ?? null, |
| 84 |
$attributes[StorageAttributes::ATTRIBUTE_EXTRA_METADATA] ?? [] |
| 85 |
); |
| 86 |
} |
| 87 |
|
| 88 |
public function jsonSerialize(): array |
| 89 |
{ |
| 90 |
return [ |
| 91 |
StorageAttributes::ATTRIBUTE_TYPE => self::TYPE_FILE, |
| 92 |
StorageAttributes::ATTRIBUTE_PATH => $this->path, |
| 93 |
StorageAttributes::ATTRIBUTE_FILE_SIZE => $this->fileSize, |
| 94 |
StorageAttributes::ATTRIBUTE_VISIBILITY => $this->visibility, |
| 95 |
StorageAttributes::ATTRIBUTE_LAST_MODIFIED => $this->lastModified, |
| 96 |
StorageAttributes::ATTRIBUTE_MIME_TYPE => $this->mimeType, |
| 97 |
StorageAttributes::ATTRIBUTE_EXTRA_METADATA => $this->extraMetadata, |
| 98 |
]; |
| 99 |
} |
| 100 |
} |
| 101 |
|