1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright (c) Florian Krämer (https://florian-kraemer.net) |
5
|
|
|
* Licensed under The MIT License |
6
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
7
|
|
|
* Redistributions of files must retain the above copyright notice. |
8
|
|
|
* |
9
|
|
|
* @copyright Copyright (c) Florian Krämer (https://florian-kraemer.net) |
10
|
|
|
* @author Florian Krämer |
11
|
|
|
* @link https://github.com/Phauthentic |
12
|
|
|
* @license https://opensource.org/licenses/MIT MIT License |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types=1); |
16
|
|
|
|
17
|
|
|
namespace Phauthentic\Infrastructure\Storage\Factories; |
18
|
|
|
|
19
|
|
|
use League\Flysystem\AdapterInterface; |
20
|
|
|
use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter; |
21
|
|
|
use MicrosoftAzure\Storage\Common\ServicesBuilder; |
22
|
|
|
use MicrosoftAzure\Storage\Blob\BlobRestProxy; |
23
|
|
|
use Phauthentic\Infrastructure\Storage\Factories\Exception\FactoryConfigException; |
24
|
|
|
use Phauthentic\Infrastructure\Storage\Factories\Exception\FactoryException; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Azure Factory |
28
|
|
|
* |
29
|
|
|
* Be aware that this adapter seems to have some problems! |
30
|
|
|
* |
31
|
|
|
* @link https://github.com/thephpleague/flysystem-azure/issues/22 |
32
|
|
|
* @link https://github.com/thephpleague/flysystem-azure/issues/15 |
33
|
|
|
*/ |
34
|
|
|
class AzureFactory extends AbstractFactory |
35
|
|
|
{ |
36
|
|
|
protected string $alias = 'azure'; |
37
|
|
|
protected ?string $package = 'league/flysystem-azure-blob-storage'; |
38
|
|
|
protected string $className = AzureBlobStorageAdapter::class; |
39
|
|
|
|
40
|
|
|
protected $endpoint = 'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @inheritDoc |
44
|
|
|
*/ |
45
|
1 |
|
public function build($config): AdapterInterface |
46
|
|
|
{ |
47
|
1 |
|
$this->availabilityCheck(); |
48
|
1 |
|
$this->checkConfig($config); |
49
|
|
|
|
50
|
1 |
|
$endpoint = sprintf( |
51
|
1 |
|
$this->endpoint, |
52
|
1 |
|
base64_encode($config['accountName']), |
53
|
1 |
|
base64_encode($config['apiKey']) |
54
|
|
|
); |
55
|
|
|
|
56
|
1 |
|
$client = BlobRestProxy::createBlobService($endpoint); |
|
|
|
|
57
|
|
|
|
58
|
1 |
|
return new AzureBlobStorageAdapter($client, $config['accountName']); |
59
|
|
|
} |
60
|
|
|
|
61
|
1 |
|
protected function checkConfig(array $config): void |
62
|
|
|
{ |
63
|
1 |
|
if (empty($config['accountName'])) { |
64
|
|
|
throw FactoryConfigException::withMissingKey('apiKey', $this); |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
if (empty($config['apiKey'])) { |
68
|
|
|
throw FactoryConfigException::withMissingKey('apiKey', $this); |
69
|
|
|
} |
70
|
1 |
|
} |
71
|
|
|
} |
72
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.