beberlei/azure-distribution-bundle
composer require brainsonic/azure-distribution-bundle
Add the bundle to config/bundles.php:
return [
// ...
Brainsonic\AzureDistributionBundle\AzureDistributionBundle::class => ['all' => true],
];
.env:
AZURE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=https;AccountName=...;AccountKey=..."
AZURE_WEBSITE_NAME="your-app-name"
use Brainsonic\AzureDistributionBundle\Service\AzureStorageService;
class FileController extends AbstractController {
public function uploadFile(AzureStorageService $azureStorage): Response {
$azureStorage->uploadFile(
'my-container',
'path/to/file.txt',
fopen('local-file.txt', 'r')
);
return new Response('File uploaded!');
}
}
Azure Blob Storage Integration:
AzureStorageService for direct file operations:
$azureStorage->uploadFile('container', 'blob-name', $fileStream);
$blobContent = $azureStorage->downloadFile('container', 'blob-name');
$containers = $azureStorage->listContainers();
$blobs = $azureStorage->listBlobs('container');
Azure Websites Deployment:
AzureWebsiteService to trigger deployments via Kudu (Azure’s deployment engine):
$websiteService->deployViaKudu(
'your-app-name',
'path/to/deploy.zip',
'https://your-app-name.scm.azurewebsites.net/api/zipdeploy'
);
AzureComposerDeployer to customize post-deploy hooks (e.g., cache warming).Environment Awareness:
AzureEnvironmentDetector to check if the app is running on Azure:
if ($detector->isOnAzure()) {
// Azure-specific logic (e.g., blob fallback for assets)
}
config/packages/cache.yaml:
framework:
cache:
app: azure_blob
pools:
azure_blob:
adapter: cache.adapter.azure_blob
provider: 'azure://DefaultEndpointsProtocol=https;AccountName=...'
// config/services.yaml
Brainsonic\AzureDistributionBundle\EventListener\AzureBlobUploadListener:
tags:
- { name: kernel.event_listener, event: azure.blob.uploaded, method: onBlobUploaded }
Deprecated SDK:
microsoft/azure-storage-blob-php). Verify compatibility:
composer show microsoft/azure-storage-blob-php
Kudu API Rate Limits:
429 Too Many Requests gracefully:
try {
$websiteService->deployViaKudu(...);
} catch (AzureHttpException $e) {
if ($e->getCode() === 429) {
sleep(5); // Retry after delay
}
}
Connection String Security:
AZURE_STORAGE_CONNECTION_STRING in .env exposes secrets. Use Azure Key Vault or Symfony’s parameter encryption:
# config/packages/security.yaml
security:
encryption_key: '%env(AZURE_ENCRYPTION_KEY)%'
Blob Leases:
$azureStorage->acquireLease('container', 'blob-name', 60); // 60-second lease
Enable Azure SDK Logging:
Add to config/packages/dev/monolog.yaml:
handlers:
azure:
type: stream
path: "%kernel.logs_dir%/azure.log"
level: debug
channels: ["azure"]
Then enable logging in your service:
$azureStorage->setLogger($logger);
Test Locally with Azure Storage Emulator: Use the Azure Storage Emulator for development:
AZURE_STORAGE_CONNECTION_STRING="UseDevelopmentStorage=true"
Custom Blob Metadata:
Extend AzureBlob to add custom metadata:
class CustomAzureBlob extends \Brainsonic\AzureDistributionBundle\Model\AzureBlob {
public function setCustomMetadata(array $metadata): void {
$this->metadata['custom'] = $metadata;
}
}
Pre-Signed URLs: Generate time-limited URLs for blob access:
$azureStorage->generateSasUrl('container', 'blob-name', '+1 hour');
Webhook Integration: Use Azure Event Grid to trigger Symfony events on blob changes. Example listener:
class AzureEventGridListener {
public function onEventGridMessage(array $event): void {
$this->eventDispatcher->dispatch(
new AzureBlobEvent($event['data']['blob']),
AzureBlobEvent::UPLOADED
);
}
}
How can I help you explore Laravel packages today?