## Getting Started
### **Minimal Setup**
1. **Installation**
Add the package via Composer (though it's primarily a dependency for other Azure Storage SDKs):
```bash
composer require azure-oss/storage-common
Note: This package is rarely installed directly—it’s a dependency for packages like azure-oss/storage-blob-php. If you’re using the full Azure Blob Storage SDK, this is auto-installed.
First Use Case If you’re working with Azure Blob Storage, Azure Data Lake Storage, or Azure File Share, this package provides:
StorageUri, StorageCredentials).StorageException, StorageError).date helper across storage-common, blob, and file share packages for consistent timestamp formatting.Example (if using azure-oss/storage-blob-php):
use Azure\Storage\Blob\BlobServiceClient;
use Azure\Storage\Common\StorageSharedKeyCredential;
$connectionString = "DefaultEndpointsProtocol=https;AccountName=...;AccountKey=...";
$credential = new StorageSharedKeyCredential(
'account-name',
'account-key'
);
$blobServiceClient = new BlobServiceClient(
'https://account-name.blob.core.windows.net',
$credential
);
Where to Look First
src/Common (models, exceptions, utilities, and SAS helpers).tests (real-world usage patterns).storage-blob-php or storage-file-php for integration examples.SharedKeyCredential (for account keys):
use Azure\Storage\Common\StorageSharedKeyCredential;
$credential = new StorageSharedKeyCredential('account-name', 'account-key');
SAS Token Support:
use Azure\Storage\Common\StorageSasCredential;
$sasToken = "sv=2020-08-04&ss=bfqt&srt=sco...";
$credential = new StorageSasCredential($sasToken);
Note: SAS token generation now uses a shared date helper for consistent timestamp formatting across packages.
Integration Tip: Reuse credentials across services (Blob, Queue, File) to avoid duplication.
date helper for SAS token generation, ensuring consistency across storage-common, blob, and file share packages.
use Azure\Storage\Common\StorageSharedKeyCredential;
use Azure\Storage\Common\Models\SharedAccessSignature;
$credential = new StorageSharedKeyCredential('account-name', 'account-key');
$sasToken = $credential->generateSharedAccessSignature(
'https://account-name.blob.core.windows.net/container/blob',
[
'startsAt' => new DateTime('2023-01-01'),
'expiresAt' => new DateTime('2023-12-31'),
'permissions' => 'rwdl'
]
);
use Azure\Storage\Common\StorageUri;
$uri = StorageUri::parse('https://account.blob.core.windows.net/container/blob');
$containerName = $uri->getContainerName(); // 'container'
BlobServiceClient).
$blobClient = new BlobServiceClient(
'https://account.blob.core.windows.net',
$credential,
[
'retry' => [
'maxRetries' => 5,
'delay' => 3, // seconds
]
]
);
Azure\Storage\Common\RetryPolicy for edge cases.try {
$blobClient->getBlobProperties('container', 'blob');
} catch (Azure\Storage\Common\StorageException $e) {
if ($e->getStatusCode() === 404) {
// Handle "not found"
}
}
$e->getErrorCode() and $e->getMessage() for debugging.use Azure\Storage\Blob\BlobServiceClient;
use Azure\Storage\Common\StorageSharedKeyCredential;
// 1. Initialize client
$blobServiceClient = new BlobServiceClient(
'https://account.blob.core.windows.net',
new StorageSharedKeyCredential('account-name', 'account-key')
);
// 2. Get container client
$containerClient = $blobServiceClient->getContainerClient('my-container');
// 3. Upload file
$blobClient = $containerClient->getBlockBlobClient('file.txt');
$blobClient->upload('local-file.txt');
StorageUri::createFromParts()) may change. Check the Blob SDK docs for breaking changes.blob and file share), ensure the shared date helper is used consistently. Older code might rely on package-specific implementations.putenv('AZURE_STORAGE_LOG_LEVEL=debug');
Logs will appear in stderr (useful for CLI scripts).StorageSharedKeyCredential or SAS token permissions.StorageUri parsing (e.g., missing / in paths).retry.maxRetries or adjust network settings.date helper is used for timestamp formatting. Older code might fail if relying on package-specific implementations.// Instead of parsing a connection string:
$connectionString = "DefaultEndpointsProtocol=https;AccountName=...;AccountKey=...";
$credential = StorageSharedKeyCredential::fromConnectionString($connectionString);
bind):
$app->bind(StorageSharedKeyCredential::class, function () {
return new StorageSharedKeyCredential(
env('AZURE_ACCOUNT_NAME'),
env('AZURE_ACCOUNT_KEY')
);
});
date helper for consistent timestamp formatting.Azure\Storage\Common\RetryPolicyInterface for custom logic (e.g., jitter delays).Azure\Storage\Common\Mock\MockStorageUri or dependency injection to stub dependencies.ReactPHP or Guzzle.date helper logic if you need custom timestamp formatting.public function register()
{
$this->app->singleton(BlobServiceClient::class, function ($app) {
return new BlobServiceClient(
config('azure.blob.endpoint'),
new StorageSharedKeyCredential(
config('azure
How can I help you explore Laravel packages today?