<?php declare(strict_types=1); namespace League\Flysystem\InMemory; use const FILEINFO_MIME_TYPE; use finfo; /** * @internal */ class InMemoryFile { private string $contents = ''; private int $lastModified = 0; private ?string $visibility = null; public function updateContents(string $contents, ?int $timestamp): void { $this->contents = $contents; $this->lastModified = $timestamp ?: time(); } public function lastModified(): int { return $this->lastModified; } public function withLastModified(int $lastModified): self { $clone = clone $this; $clone->lastModified = $lastModified; return $clone; } public function read(): string { return $this->contents; } /** * @return resource */ public function readStream() { /** @var resource $stream */ $stream = fopen('php://temp', 'w+b'); fwrite($stream, $this->contents); rewind($stream); return $stream; } public function fileSize(): int { return strlen($this->contents); } public function mimeType(): string { return (string) (new finfo(FILEINFO_MIME_TYPE))->buffer($this->contents); } public function setVisibility(string $visibility): void { $this->visibility = $visibility; } public function visibility(): ?string { return $this->visibility; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
.github | Folder | 0755 |
|
|
.gitattributes | File | 122 B | 0644 |
|
InMemoryFile.php | File | 1.51 KB | 0644 |
|
InMemoryFilesystemAdapter.php | File | 8.32 KB | 0644 |
|
InMemoryFilesystemAdapterTest.php | File | 9.17 KB | 0644 |
|
README.md | File | 317 B | 0644 |
|
StaticInMemoryAdapterRegistry.php | File | 484 B | 0644 |
|
StaticInMemoryAdapterRegistryTest.php | File | 1.74 KB | 0644 |
|
composer.json | File | 662 B | 0644 |
|