Skip to content

ObjectMetadata

The subset of a stored object’s HEAD response worth typing: everything else a provider returns (storage class, versioning, generation, SSE and custom metadata headers) is available from the raw response via the client’s own request() method for callers that need it.

Every field is nullable because a HEAD response is not contractually obliged to carry it — a proxy or an S3-compatible server may omit Content-Length or ETag, and callers that require a value should say so with their own error rather than get a silently invented zero.

Shared across providers: the three fields and their parsing are HTTP semantics, not provider semantics, so S3, GCS and Azure describe an object the same way.

final readonly class ObjectMetadata

Since3.2.0
SourceObjectMetadata.php
PropertyTypeDescription
$contentLength?``intreadonly.
$etag?``stringreadonly.
$lastModified?DateTimeImmutablereadonly.

public function __construct(?int $contentLength, ?DateTimeImmutable $lastModified, ?string $etag): mixed

ParameterTypeDescription
$contentLength?``int
$lastModified?DateTimeImmutable
$etag?``string

Returns mixed

MethodDescription
fromResponse(ResponseInterface $response): ObjectMetadataReads the typed fields out of a HEAD (or GET) response’s headers.

public static function fromResponse(ResponseInterface $response): ObjectMetadata

Reads the typed fields out of a HEAD (or GET) response’s headers.

Each field independently becomes null when its header is absent or unusable: a Content-Length that is not all digits, an unparseable Last-Modified, an empty ETag. Nothing throws — a response with none of the three headers yields an all-null instance.

ParameterTypeDescription
$responseResponseInterface

Returns ObjectMetadata