Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Azure Storage Blob filesystem driver for Laravel

[![Latest Version on Packagist](https://img.shields.io/packagist/v/azure-oss/storage-blob-laravel.svg)](https://packagist.org/packages/azure-oss/storage-blob-laravel)
[![Packagist Downloads](https://img.shields.io/packagist/dm/azure-oss/storage-blob-laravel)](https://packagist.org/packages/azure-oss/storage-blob-laravel)
A fork of [Azure-OSS/azure-storage-php-adapter-laravel](https://github.com/Azure-OSS/azure-storage-php-adapter-laravel) with BIIGLE-specific modifications.

## Minimum Requirements

Expand All @@ -11,7 +10,7 @@

Install the package using composer:
```shell
composer require azure-oss/storage-blob-laravel
composer require biigle/laravel-azure-storage
```


Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "azure-oss/storage-blob-laravel",
"name": "biigle/laravel-azure-storage",
"description": "Azure Storage Blob filesystem driver for Laravel",
"type": "library",
"license": "MIT",
Expand All @@ -17,6 +17,10 @@
{
"name": "Brecht Vermeersch",
"email": "brechtvermeersch@outlook.be"
},
{
"name": "Martin Zurowietz",
"email": "m.zurowietz@uni-bielefeld.de"
}
],
"require": {
Expand Down
32 changes: 25 additions & 7 deletions src/AzureStorageBlobAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use AzureOss\FlysystemAzureBlobStorage\AzureBlobStorageAdapter;
use AzureOss\Storage\Blob\BlobServiceClient;
use AzureOss\Storage\Common\Auth\StorageSharedKeyCredential;
use Illuminate\Filesystem\FilesystemAdapter;
use League\Flysystem\Config;
use League\Flysystem\Filesystem;
use League\Flysystem\UnableToGenerateTemporaryUrl;

/**
* @internal
Expand All @@ -15,14 +17,22 @@
*/
final class AzureStorageBlobAdapter extends FilesystemAdapter
{
/**
* Set to true to use the direct public URL instead of generating a temporary URL.
* If true, also acts as a fallback for new temporary URLs if no account credentials
* were provided.
*/
public bool $useDirectPublicUrl;

/**
* @param array{connection_string: string, container: string, prefix?: string, root?: string} $config
*/
public function __construct(array $config)
{
$useDirectPublicUrl = $config['use_direct_public_url'] ?? false;
$serviceClient = BlobServiceClient::fromConnectionString($config['connection_string']);
$containerClient = $serviceClient->getContainerClient($config['container']);
$adapter = new AzureBlobStorageAdapter($containerClient, $config['prefix'] ?? $config['root'] ?? '');
$adapter = new AzureBlobStorageAdapter($containerClient, $config['prefix'] ?? $config['root'] ?? '', useDirectPublicUrl: $useDirectPublicUrl);

parent::__construct(
new Filesystem($adapter, $config),
Expand All @@ -43,7 +53,7 @@ public function url($path)
*/
public function providesTemporaryUrls()
{
return true;
return $this->adapter->containerClient->sharedKeyCredentials instanceof StorageSharedKeyCredential || $this->useDirectPublicUrl;
}

/**
Expand All @@ -56,11 +66,19 @@ public function providesTemporaryUrls()
/** @phpstan-ignore-next-line */
public function temporaryUrl($path, $expiration, array $options = [])
{
return $this->adapter->temporaryUrl(
$path,
$expiration,
new Config(array_merge(['permissions' => 'r'], $options))
);
try {
return $this->adapter->temporaryUrl(
$path,
$expiration,
new Config(array_merge(['permissions' => 'r'], $options))
);
} catch (UnableToGenerateTemporaryUrl $e) {
if ($this->useDirectPublicUrl) {
return $this->url($path);
} else {
throw $e;
}
}
}

/**
Expand Down