forked from jkapuscik2/design-patterns-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAzureFileStorage.php
More file actions
36 lines (25 loc) · 1.12 KB
/
AzureFileStorage.php
File metadata and controls
36 lines (25 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
namespace Structural\Adapter;
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
use Symfony\Component\Dotenv\Dotenv;
class AzureFileStorage implements FileAdapter {
private $client;
private $containerName;
public function __construct () {
$dotenv = new Dotenv();
$dotenv->load('.env');
$connectionString = "DefaultEndpointsProtocol=https;AccountName=" . getenv('AZURE_ACCOUNT_NAME') . ";AccountKey=" . getenv("AZURE_ACCOUNT_KEY") . ";EndpointSuffix=core.windows.net";
$this->client = BlobRestProxy::createBlobService($connectionString);
$this->containerName = getenv("AZURE_CONTAINER_NAME");
}
public function get (string $name): File {
$blob = $this->client->getBlob($this->containerName, $name);
return new File($name, stream_get_contents($blob->getContentStream()));
}
public function save (string $path, string $name): void {
$this->client->createBlockBlob($this->containerName, $name, fopen($path, "r"));
}
public function delete (string $name): void {
$this->client->deleteBlob($this->containerName, $name);
}
}