Skip to content

AzureBlobClient

Minimal Azure Blob Storage REST client, deliberately not built on the official microsoft/azure-storage-blob SDK (Microsoft stopped actively developing it; a hand-rolled client against the documented REST API has proven more maintainable in production).

Only the operations the session and filesystem backends need: ensure-container, get, put, delete, get-properties and list. No chunked upload or snapshots.

Those absent operations are still reachable: AzureBlobClient::request() authorizes the request the same way every other method does and hands back the raw PSR-7 response, so a caller can implement the operation it needs without reimplementing the authorization.

Authorization itself, Shared Key or an Azure AD bearer token from workload identity or the Azure CLI, is delegated to an AzureCredential, not built in here.

final class AzureBlobClient

SourceAzureBlobClient.php

public function __construct(ClientInterface $httpClient, string $accountName, AzureCredential $credential, ?string $endpoint = null, Psr17Factory $psr17 = new Psr17Factory(…)): mixed

ParameterTypeDescription
$httpClientClientInterface
$accountNamestring
$credentialAzureCredential
$endpoint?``string
$psr17Psr17Factory

Returns mixed

MethodDescription
delete(string $container, string $blob): voidDeletes a blob, treating a missing one as success.
ensureContainerExists(string $container): voidCreates the container, treating “already exists” as success.
get(string $container, string $blob): ?stringReturns the blob’s contents, or null if Azure answers 404.
head(string $container, string $blob): ?ObjectMetadataBlob properties without transferring the body (Get Blob Properties), or null if the blob does not exist.
listObjects(string $container, string $prefix = '', string $delimiter = '', ?string $continuationToken = null, int $maxKeys = 1000): ObjectListingLists blobs in $container whose name starts with $prefix, one page at a time (List Blobs).
put(string $container, string $blob, string $data): voidCreates or replaces a block blob in one request.
request(string $method, string $path, array<string, string> $query = [], array<string, string> $headers = [], ?string $body = null): ResponseInterfaceSend an arbitrary signed request and return the raw response, for operations this class does not model itself.

public function delete(string $container, string $blob): void

Deletes a blob, treating a missing one as success.

A 404 returns normally so a delete is idempotent.

ParameterTypeDescription
$containerstring
$blobstring
ThrowsWhen
AzureStorageExceptionOn any other 4xx/5xx status, or a transport failure that survived the retries.

public function ensureContainerExists(string $container): void

Creates the container, treating “already exists” as success.

A 409 from Azure means another caller got there first, which is the desired end state, so 201, 202 and 409 all return normally.

ParameterTypeDescription
$containerstring
ThrowsWhen
AzureStorageExceptionOn any other status, or if the request could not be sent after the configured retries.

public function get(string $container, string $blob): ?string

Returns the blob’s contents, or null if Azure answers 404.

A container that does not exist also answers 404, so it is indistinguishable from a missing blob here.

ParameterTypeDescription
$containerstring
$blobstring

Returns ?``string

ThrowsWhen
AzureStorageExceptionOn any other 4xx/5xx status, or a transport failure that survived the retries.

public function head(string $container, string $blob): ?ObjectMetadata

Blob properties without transferring the body (Get Blob Properties), or null if the blob does not exist.

ParameterTypeDescription
$containerstring
$blobstring

Returns ?ObjectMetadata

public function listObjects(string $container, string $prefix = '', string $delimiter = '', ?string $continuationToken = null, int $maxKeys = 1000): ObjectListing

Lists blobs in $container whose name starts with $prefix, one page at a time (List Blobs).

$continuationToken must be null on the first call and, for a truncated result, the previous call’s ObjectListing::$nextContinuationToken verbatim on the next; it carries Azure’s own NextMarker and is opaque to a caller.

ParameterTypeDescription
$containerstring
$prefixstring
$delimiterstring
$continuationToken?``string
$maxKeysint

Returns ObjectListing

ThrowsWhen
AzureStorageExceptionOn any 4xx/5xx status, a transport failure that survived the retries, or a response body that was not the XML this expects.

public function put(string $container, string $blob, string $data): void

Creates or replaces a block blob in one request.

The whole payload is sent in a single PUT with an application/octet-stream content type; there is no chunked upload, so the data must fit Azure’s single-request block blob limit. The container must already exist.

ParameterTypeDescription
$containerstring
$blobstring
$datastring
ThrowsWhen
AzureStorageExceptionIf Azure answers 4xx/5xx, or the request could not be sent after the retries.

public function request(string $method, string $path, array<string, string> $query = [], array<string, string> $headers = [], ?string $body = null): ResponseInterface

Send an arbitrary signed request and return the raw response, for operations this class does not model itself.

ParameterTypeDescription
$methodstring
$pathstring
$queryarray``<``string``, ``string``>signed as part of the canonicalized resource
$headersarray``<``string``, ``string``>
$body?``string

Returns ResponseInterface