Skip to content

Commit 3a30e52

Browse files
committed
first commit
0 parents  commit 3a30e52

File tree

5 files changed

+181
-0
lines changed

5 files changed

+181
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.idea
2+
vendor
3+
composer.lock
4+
bin
5+
coverage
6+
coverage.xml
7+
composer.lock

LICENCE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2018 Jason Judge
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
## Configuration in `config/filesystems.php`:
3+
4+
```php
5+
[
6+
...
7+
'disks' => [
8+
...
9+
// Call this disk what you like.
10+
'azure-file-storage' => [
11+
// This driver.
12+
'driver' => 'azure-file-storage',
13+
14+
// Account credentials.
15+
'storageAccount' => env('AZURE_FLE_STORAGE_ACCOUNT'),
16+
'storageAccessKey' => env('AZURE_FLE_STORAGE_ACCESS_KEY'),
17+
18+
// The file share.
19+
// This driver supports one file share at a time (you cannot
20+
// copy or move files between shares natively).
21+
'fileShareName' => env('AZURE_FLE_STORAGE_HARE_NAME'),
22+
23+
// Optional settings
24+
'disableRecursiveDelete' => false,
25+
'driverOptions' => [],
26+
],
27+
]
28+
];
29+
```
30+
31+
## Usage
32+
33+
See [the Laravel documentation](https://laravel.com/docs/5.5/filesystem)
34+
for general usage of a file system in Laravel.
35+
A simple example follows:
36+
37+
```
38+
use Storage;
39+
40+
// List all files recursively from the root of the Azure share:
41+
42+
$files = Storage::disk('azure-file-storage')->listAll();
43+
44+
// Example:
45+
// array:25 [▼
46+
// 0 => "file1.txt"
47+
// 1 => "foo/file2.txt"
48+
// 2 => "foo/dee/dar/bigfile.txt"
49+
// ]
50+
```
51+

composer.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "academe/laravel-azure-file-storage-driver",
3+
"description": "Azure File Storage filesystem driver for Laravel.",
4+
"homepage": "https://github.com/academe",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Jason Judge",
9+
"email": "jason@academe.co.uk"
10+
}
11+
],
12+
"support": {
13+
"issues": "https://github.com/academe/laravel-azure-file-storage-driver/issues"
14+
},
15+
"keywords": [
16+
"laravel",
17+
"driver",
18+
"azure",
19+
"file storage"
20+
],
21+
"autoload": {
22+
"psr-4": {
23+
"Academe\\Laravel\\AzureFileStorageDriver\\": "src"
24+
}
25+
},
26+
"autoload-dev": {
27+
"psr-4": {
28+
"Academe\\Laravel\\AzureFileStorageDriver\\Tests\\": "tests"
29+
}
30+
},
31+
"require": {
32+
"php": ">=7.0",
33+
"consilience/flysystem-azure-file-storage": "dev-master"
34+
},
35+
"require-dev": {
36+
"phpunit/phpunit": "^6.0|^7.0",
37+
"orchestra/testbench": "~3.3|~3.4|~3.5|~3.6"
38+
},
39+
"extra": {
40+
"laravel": {
41+
"providers": [
42+
"Academe\\Laravel\\AzureFileStorageDriver\\ServiceProvider"
43+
]
44+
}
45+
}
46+
}

src/ServiceProvider.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace Academe\Laravel\AzureFileStorageDriver;
4+
5+
use Storage;
6+
use League\Flysystem\Filesystem;
7+
8+
use Consilience\Flysystem\Azure\AzureFileAdapter;
9+
use MicrosoftAzure\Storage\File\FileRestProxy;
10+
use Illuminate\Support\ServiceProvider as ServiceProviderContract;
11+
12+
class ServiceProvider extends ServiceProviderContract
13+
{
14+
/**
15+
* Bootstrap the application services.
16+
*/
17+
public function boot()
18+
{
19+
Storage::extend('azure-file-storage', function ($app, $config) {
20+
$connectionString = sprintf(
21+
'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s',
22+
$config['storageAccount'],
23+
$config['storageAccessKey']
24+
);
25+
26+
$driverConfig = [
27+
'endpoint' => $connectionString,
28+
'container' => $config['fileShareName'],
29+
'disableRecursiveDelete' => !empty($config['disableRecursiveDelete']),
30+
];
31+
32+
$fileService = FileRestProxy::createFileService(
33+
$connectionString,
34+
[] // $optionsWithMiddlewares
35+
);
36+
37+
$driverOptions = !empty($config['driverOptions'])
38+
? $config['driverOptions']
39+
: null;
40+
41+
return new Filesystem(
42+
new AzureFileAdapter(
43+
$fileService,
44+
$driverConfig,
45+
$driverOptions
46+
)
47+
);
48+
});
49+
}
50+
51+
/**
52+
* Register the application services.
53+
*/
54+
public function register()
55+
{
56+
//
57+
}
58+
}

0 commit comments

Comments
 (0)