Skip to content

ObjectStoreFilesystemAdapter

A FilesystemAdapterInterface over any ObjectStoreClientInterface.

Every keyed object store maps onto a filesystem the same way — prefix the path to form a key, translate a missing object into a not-found error, and read size and modification time out of the object’s metadata. That mapping is provider-independent, so it lives here once and the provider packages supply only their client.

Not a ListableFilesystemInterface itself: that needs a store that can enumerate its keys, which not every ObjectStoreClientInterface can. ListableObjectStoreFilesystemAdapter adds it for the ones that can, without every consumer of this class paying for the distinction.

The provider name is carried for error messages only, so a failure says “S3 returned no * Content-Length” rather than something a reader has to trace back to a driver alias.

readonly class ObjectStoreFilesystemAdapter implements FilesystemAdapterInterface

ImplementsFilesystemAdapterInterface
Since3.2.0
SourceObjectStoreFilesystemAdapter.php

public function __construct(ObjectStoreClientInterface $client, string $providerName, string $keyPrefix = ''): mixed

Prepended to every path to form the object key.

ParameterTypeDescription
$clientObjectStoreClientInterfaceThe store, already bound to its bucket or container.
$providerNamestringNamed in error messages, e.g. ‘S3’, ‘GCS’, ‘Azure’.
$keyPrefixstringPrepended to every path to form the object key.

Returns mixed

MethodDescription
delete(string $path): voidDeletes the object under $path.
exists(string $path): boolReports whether the store holds an object under $path.
lastModified(string $path): DateTimeImmutableReturns the object’s modification time, taken from its Last-Modified metadata.
read(string $path): stringReturns the body of the object stored under $path.
size(string $path): intReturns the object’s size in bytes, taken from its Content-Length metadata.
write(string $path, string $contents): voidStores $contents as the object under $path, replacing any existing object.

public function delete(string $path): void

Deletes the object under $path.

Deleting a key the store does not hold is not an error — object stores treat delete as idempotent — so only a transport or authorization failure is reported.

ParameterTypeDescription
$pathstring
ThrowsWhen
FilesystemStorageExceptionIf the store rejected the delete.

public function exists(string $path): bool

Reports whether the store holds an object under $path.

Costs a metadata request, not a download.

ParameterTypeDescription
$pathstring

Returns bool

ThrowsWhen
FilesystemStorageExceptionIf the metadata request failed for a reason other than the object being absent.

public function lastModified(string $path): DateTimeImmutable

Returns the object’s modification time, taken from its Last-Modified metadata.

A provider that omits the header, or sends one that could not be parsed, is reported as a failure naming the provider rather than defaulting to the current time.

ParameterTypeDescription
$pathstring

Returns DateTimeImmutable

ThrowsWhen
FileNotFoundStorageExceptionIf the store holds no object under $path.
FilesystemStorageExceptionIf the metadata carried no usable modification time.

public function read(string $path): string

Returns the body of the object stored under $path.

ParameterTypeDescription
$pathstring

Returns string

ThrowsWhen
FileNotFoundStorageExceptionIf the store reports no object for that key.
FilesystemStorageExceptionIf the store call itself failed.

public function size(string $path): int

Returns the object’s size in bytes, taken from its Content-Length metadata.

A provider that answers the metadata request without a usable Content-Length is a failure, not a zero-length file, and is reported naming the provider.

ParameterTypeDescription
$pathstring

Returns int

ThrowsWhen
FileNotFoundStorageExceptionIf the store holds no object under $path.
FilesystemStorageExceptionIf the metadata carried no content length.

public function write(string $path, string $contents): void

Stores $contents as the object under $path, replacing any existing object.

ParameterTypeDescription
$pathstring
$contentsstring
ThrowsWhen
FilesystemStorageExceptionIf the store rejected the put; the provider’s own exception is kept as the previous exception.