Skip to content

Commit 3c9489c

Browse files
committed
Added AzureFilesystem
1 parent 15f3b88 commit 3c9489c

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

src/AzureFilesystem.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* @link https://github.com/creocoder/yii2-flysystem
4+
* @copyright Copyright (c) 2015 Alexander Kochetov
5+
* @license http://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
namespace creocoder\flysystem;
9+
10+
use League\Flysystem\Azure\AzureAdapter;
11+
use WindowsAzure\Common\ServicesBuilder;
12+
use Yii;
13+
use yii\base\InvalidConfigException;
14+
15+
/**
16+
* AzureFilesystem
17+
*
18+
* @author Alexander Kochetov <[email protected]>
19+
*/
20+
class AzureFilesystem extends Filesystem
21+
{
22+
/**
23+
* @var string
24+
*/
25+
public $accountName;
26+
/**
27+
* @var string
28+
*/
29+
public $accountKey;
30+
/**
31+
* @var string
32+
*/
33+
public $container;
34+
35+
/**
36+
* @inheritdoc
37+
*/
38+
public function init()
39+
{
40+
if ($this->accountName === null) {
41+
throw new InvalidConfigException('The "accountName" property must be set.');
42+
}
43+
44+
if ($this->accountKey === null) {
45+
throw new InvalidConfigException('The "accountKey" property must be set.');
46+
}
47+
48+
if ($this->container === null) {
49+
throw new InvalidConfigException('The "container" property must be set.');
50+
}
51+
52+
parent::init();
53+
}
54+
55+
/**
56+
* @return AzureAdapter
57+
*/
58+
protected function prepareAdapter()
59+
{
60+
return new AzureAdapter(
61+
ServicesBuilder::getInstance()->createBlobService(sprintf(
62+
'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s',
63+
base64_encode($this->accountName),
64+
base64_encode($this->accountKey)
65+
)),
66+
$this->container
67+
);
68+
}
69+
}

0 commit comments

Comments
 (0)