This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from rymanalu/storage-url
Added getUrl method to support Storage::url
- Loading branch information
Showing
6 changed files
with
72 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ vendor/ | |
composer.lock | ||
build/ | ||
infection-log.txt | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Matthewbdaly\LaravelAzureStorage; | ||
|
||
use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter as BaseAzureBlobStorageAdapter; | ||
use MicrosoftAzure\Storage\Blob\BlobRestProxy; | ||
|
||
class AzureBlobStorageAdapter extends BaseAzureBlobStorageAdapter | ||
{ | ||
/** | ||
* Base file URL. | ||
* | ||
* @var string | ||
*/ | ||
protected $baseFileUrl; | ||
|
||
/** | ||
* Create a new AzureBlobStorageAdapter instance. | ||
* | ||
* @param \MicrosoftAzure\Storage\Blob\BlobRestProxy $client | ||
* @param string $container | ||
* @param string|null $prefix | ||
*/ | ||
public function __construct(BlobRestProxy $client, $container, $prefix = null) | ||
{ | ||
parent::__construct($client, $container, $prefix); | ||
|
||
$this->baseFileUrl = $client->getPsrPrimaryUri().$container; | ||
} | ||
|
||
/** | ||
* Get the file URL by given path. | ||
* | ||
* @param string $path | ||
* @return string | ||
*/ | ||
public function getUrl($path) | ||
{ | ||
return $this->baseFileUrl.'/'.$path; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Tests; | ||
|
||
use Matthewbdaly\LaravelAzureStorage\AzureBlobStorageAdapter; | ||
use MicrosoftAzure\Storage\Blob\BlobRestProxy; | ||
|
||
class AzureBlobStorageAdapterTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_correctly_generates_the_file_url() | ||
{ | ||
$client = BlobRestProxy::createBlobService('DefaultEndpointsProtocol=https;AccountName=azure_account;AccountKey='.base64_encode('azure_key')); | ||
|
||
$adapter = new AzureBlobStorageAdapter($client, 'azure_container'); | ||
|
||
$this->assertEquals('https://azure_account.blob.core.windows.net/azure_container/test.txt', $adapter->getUrl('test.txt')); | ||
} | ||
|
||
/** @test */ | ||
public function it_now_supports_the_url_method() | ||
{ | ||
$storage = $this->app['filesystem']; | ||
|
||
$this->assertEquals('https://my_azure_storage_name.blob.core.windows.net/MY_AZURE_STORAGE_CONTAINER/test.txt', $storage->url('test.txt')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters