1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* BsbFlystem |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @see https://bushbaby.nl/ |
10
|
|
|
* |
11
|
|
|
* @copyright Copyright (c) 2014-2021 bushbaby multimedia. (https://bushbaby.nl) |
12
|
|
|
* @author Bas Kamer <[email protected]> |
13
|
|
|
* @license MIT |
14
|
|
|
* |
15
|
|
|
* @package bushbaby/flysystem |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
declare(strict_types=1); |
19
|
|
|
|
20
|
|
|
namespace BsbFlysystem\Adapter\Factory; |
21
|
|
|
|
22
|
|
|
use BsbFlysystem\Exception\RequirementsException; |
23
|
|
|
use BsbFlysystem\Exception\UnexpectedValueException; |
24
|
|
|
use League\Flysystem\AdapterInterface; |
25
|
|
|
use League\Flysystem\Azure\AzureAdapter as Adapter; |
26
|
|
|
use MicrosoftAzure\Storage\Common\ServicesBuilder; |
27
|
|
|
use Psr\Container\ContainerInterface; |
28
|
|
|
|
29
|
|
|
class AzureAdapterFactory extends AbstractAdapterFactory |
30
|
|
|
{ |
31
|
|
|
public function doCreateService(ContainerInterface $container): AdapterInterface |
32
|
|
|
{ |
33
|
|
|
if (! \class_exists(Adapter::class)) { |
34
|
|
|
throw new RequirementsException(['league/flysystem-azure'], 'Azure'); |
35
|
|
|
} |
36
|
4 |
|
$endpoint = \sprintf( |
37
|
|
|
'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s', |
38
|
4 |
|
$this->options['account-name'], |
39
|
1 |
|
$this->options['account-key'] |
40
|
|
|
); |
41
|
|
|
|
42
|
3 |
|
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($endpoint); |
43
|
1 |
|
|
44
|
|
|
return new Adapter($blobRestProxy, $this->options['container']); |
45
|
|
|
} |
46
|
2 |
|
|
47
|
1 |
|
protected function validateConfig(): void |
48
|
|
|
{ |
49
|
1 |
|
if (! isset($this->options['account-name'])) { |
50
|
|
|
throw new UnexpectedValueException("Missing 'account-name' as option"); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if (! isset($this->options['account-key'])) { |
54
|
|
|
throw new UnexpectedValueException("Missing 'account-key' as option"); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if (! isset($this->options['container'])) { |
58
|
|
|
throw new UnexpectedValueException("Missing 'container' as option"); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|