brainsonic/azure-distribution-bundle
Installation Add the bundle via Composer:
composer require brainsonic/azure-distribution-bundle
Enable it in config/bundles.php:
return [
// ...
Brainsonic\AzureDistributionBundle\AzureDistributionBundle::class => ['all' => true],
];
Configuration Publish the default config:
php bin/console brainsonic:azure:install
Update config/packages/azure_distribution.yaml with your Azure credentials:
azure_distribution:
account_name: 'your-storage-account'
account_key: 'your-storage-key'
blob_service: 'https://your-account.blob.core.windows.net'
First Use Case: Blob Storage Upload a file to Azure Blob Storage:
use Brainsonic\AzureDistributionBundle\Service\BlobService;
class SomeController
{
public function uploadFile(BlobService $blobService)
{
$blobService->upload('container-name', 'file.txt', '/path/to/local/file.txt');
}
}
Blob Storage Operations
$blobService->upload('container', 'remote-file.txt', '/local/path/file.txt');
$blobService->download('container', 'remote-file.txt', '/local/path/');
$blobService->listContainers();
$blobService->listBlobs('container-name');
Table Storage (NoSQL)
$tableService->insert('entity-name', ['PartitionKey' => 'key', 'RowKey' => 'row', 'data' => 'value']);
$tableService->get('entity-name', 'key', 'row');
Queue Storage
$queueService->createQueue('queue-name');
$queueService->sendMessage('queue-name', 'message-data');
$queueService->getMessages('queue-name', 10);
BlobService, TableService).azure.distribution.* events (e.g., post-upload hooks).config/packages/azure_distribution.yaml for environment-specific settings (e.g., staging vs. production).Authentication Errors
account_name and account_key are correct and have the right permissions (e.g., Storage Blob Data Contributor).Container/Blob Existence
$blobService->createContainer('container-name', 'public'); // 'public' for public access
if (!$blobService->containerExists('container-name')) { ... }
CORS Issues
$blobService->setCorsRules('container-name', [
['AllowedOrigins' => ['*'], 'AllowedMethods' => ['GET', 'PUT']],
]);
config/packages/monolog.yaml:
handlers:
azure:
type: stream
path: "%kernel.logs_dir%/%azure_distribution%.log"
level: debug
channels: ["azure"]
$blobService->getClient()->getBlobRestProxy()->setDebug(true);
Custom Services
Extend the base services (e.g., BlobService) by creating a decorator:
use Brainsonic\AzureDistributionBundle\Service\BlobServiceInterface;
class CustomBlobService implements BlobServiceInterface
{
private $decorated;
public function __construct(BlobService $decorated) { $this->decorated = $decorated; }
public function upload($container, $blob, $filePath)
{
// Pre/post-processing logic
$this->decorated->upload($container, $blob, $filePath);
}
}
Register the decorator in services.yaml:
services:
Brainsonic\AzureDistributionBundle\Service\BlobService: '@custom_blob_service'
custom_blob_service:
class: App\Service\CustomBlobService
arguments: ['@azure_distribution.blob_service']
Event Subscribers
Listen for events like azure.distribution.blob.uploaded:
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Brainsonic\AzureDistributionBundle\Event\BlobEvent;
class AzureEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'azure.distribution.blob.uploaded' => 'onBlobUploaded',
];
}
public function onBlobUploaded(BlobEvent $event)
{
// Custom logic (e.g., log, notify)
}
}
Azure SDK Updates
composer.json to avoid unexpected updates:
"require": {
"windowsazure/azure-sdk-for-php": "~0.5.0"
}
How can I help you explore Laravel packages today?