@@ -25,85 +25,85 @@ |
||
| 25 | 25 | use OCP\Files\ObjectStore\IObjectStore; |
| 26 | 26 | |
| 27 | 27 | class Azure implements IObjectStore { |
| 28 | - /** @var string */ |
|
| 29 | - private $containerName; |
|
| 30 | - /** @var string */ |
|
| 31 | - private $accountName; |
|
| 32 | - /** @var string */ |
|
| 33 | - private $accountKey; |
|
| 34 | - /** @var BlobRestProxy|null */ |
|
| 35 | - private $blobClient = null; |
|
| 36 | - /** @var string|null */ |
|
| 37 | - private $endpoint = null; |
|
| 38 | - /** @var bool */ |
|
| 39 | - private $autoCreate = false; |
|
| 28 | + /** @var string */ |
|
| 29 | + private $containerName; |
|
| 30 | + /** @var string */ |
|
| 31 | + private $accountName; |
|
| 32 | + /** @var string */ |
|
| 33 | + private $accountKey; |
|
| 34 | + /** @var BlobRestProxy|null */ |
|
| 35 | + private $blobClient = null; |
|
| 36 | + /** @var string|null */ |
|
| 37 | + private $endpoint = null; |
|
| 38 | + /** @var bool */ |
|
| 39 | + private $autoCreate = false; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param array $parameters |
|
| 43 | - */ |
|
| 44 | - public function __construct($parameters) { |
|
| 45 | - $this->containerName = $parameters['container']; |
|
| 46 | - $this->accountName = $parameters['account_name']; |
|
| 47 | - $this->accountKey = $parameters['account_key']; |
|
| 48 | - if (isset($parameters['endpoint'])) { |
|
| 49 | - $this->endpoint = $parameters['endpoint']; |
|
| 50 | - } |
|
| 51 | - if (isset($parameters['autoCreate'])) { |
|
| 52 | - $this->autoCreate = $parameters['autoCreate']; |
|
| 53 | - } |
|
| 54 | - } |
|
| 41 | + /** |
|
| 42 | + * @param array $parameters |
|
| 43 | + */ |
|
| 44 | + public function __construct($parameters) { |
|
| 45 | + $this->containerName = $parameters['container']; |
|
| 46 | + $this->accountName = $parameters['account_name']; |
|
| 47 | + $this->accountKey = $parameters['account_key']; |
|
| 48 | + if (isset($parameters['endpoint'])) { |
|
| 49 | + $this->endpoint = $parameters['endpoint']; |
|
| 50 | + } |
|
| 51 | + if (isset($parameters['autoCreate'])) { |
|
| 52 | + $this->autoCreate = $parameters['autoCreate']; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @return BlobRestProxy |
|
| 58 | - */ |
|
| 59 | - private function getBlobClient() { |
|
| 60 | - if (!$this->blobClient) { |
|
| 61 | - $protocol = $this->endpoint ? substr($this->endpoint, 0, strpos($this->endpoint, ':')) : 'https'; |
|
| 62 | - $connectionString = "DefaultEndpointsProtocol=" . $protocol . ";AccountName=" . $this->accountName . ";AccountKey=" . $this->accountKey; |
|
| 63 | - if ($this->endpoint) { |
|
| 64 | - $connectionString .= ';BlobEndpoint=' . $this->endpoint; |
|
| 65 | - } |
|
| 66 | - $this->blobClient = BlobRestProxy::createBlobService($connectionString); |
|
| 56 | + /** |
|
| 57 | + * @return BlobRestProxy |
|
| 58 | + */ |
|
| 59 | + private function getBlobClient() { |
|
| 60 | + if (!$this->blobClient) { |
|
| 61 | + $protocol = $this->endpoint ? substr($this->endpoint, 0, strpos($this->endpoint, ':')) : 'https'; |
|
| 62 | + $connectionString = "DefaultEndpointsProtocol=" . $protocol . ";AccountName=" . $this->accountName . ";AccountKey=" . $this->accountKey; |
|
| 63 | + if ($this->endpoint) { |
|
| 64 | + $connectionString .= ';BlobEndpoint=' . $this->endpoint; |
|
| 65 | + } |
|
| 66 | + $this->blobClient = BlobRestProxy::createBlobService($connectionString); |
|
| 67 | 67 | |
| 68 | - if ($this->autoCreate) { |
|
| 69 | - $this->blobClient->createContainer($this->containerName); |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - return $this->blobClient; |
|
| 73 | - } |
|
| 68 | + if ($this->autoCreate) { |
|
| 69 | + $this->blobClient->createContainer($this->containerName); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + return $this->blobClient; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @return string the container or bucket name where objects are stored |
|
| 77 | - */ |
|
| 78 | - public function getStorageId() { |
|
| 79 | - return 'azure::blob::' . $this->containerName; |
|
| 80 | - } |
|
| 75 | + /** |
|
| 76 | + * @return string the container or bucket name where objects are stored |
|
| 77 | + */ |
|
| 78 | + public function getStorageId() { |
|
| 79 | + return 'azure::blob::' . $this->containerName; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @param string $urn the unified resource name used to identify the object |
|
| 84 | - * @return resource stream with the read data |
|
| 85 | - * @throws \Exception when something goes wrong, message will be logged |
|
| 86 | - */ |
|
| 87 | - public function readObject($urn) { |
|
| 88 | - $blob = $this->getBlobClient()->getBlob($this->containerName, $urn); |
|
| 89 | - return $blob->getContentStream(); |
|
| 90 | - } |
|
| 82 | + /** |
|
| 83 | + * @param string $urn the unified resource name used to identify the object |
|
| 84 | + * @return resource stream with the read data |
|
| 85 | + * @throws \Exception when something goes wrong, message will be logged |
|
| 86 | + */ |
|
| 87 | + public function readObject($urn) { |
|
| 88 | + $blob = $this->getBlobClient()->getBlob($this->containerName, $urn); |
|
| 89 | + return $blob->getContentStream(); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * @param string $urn the unified resource name used to identify the object |
|
| 94 | - * @param resource $stream stream with the data to write |
|
| 95 | - * @throws \Exception when something goes wrong, message will be logged |
|
| 96 | - */ |
|
| 97 | - public function writeObject($urn, $stream) { |
|
| 98 | - $this->getBlobClient()->createBlockBlob($this->containerName, $urn, $stream); |
|
| 99 | - } |
|
| 92 | + /** |
|
| 93 | + * @param string $urn the unified resource name used to identify the object |
|
| 94 | + * @param resource $stream stream with the data to write |
|
| 95 | + * @throws \Exception when something goes wrong, message will be logged |
|
| 96 | + */ |
|
| 97 | + public function writeObject($urn, $stream) { |
|
| 98 | + $this->getBlobClient()->createBlockBlob($this->containerName, $urn, $stream); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * @param string $urn the unified resource name used to identify the object |
|
| 103 | - * @return void |
|
| 104 | - * @throws \Exception when something goes wrong, message will be logged |
|
| 105 | - */ |
|
| 106 | - public function deleteObject($urn) { |
|
| 107 | - $this->getBlobClient()->deleteBlob($this->containerName, $urn); |
|
| 108 | - } |
|
| 101 | + /** |
|
| 102 | + * @param string $urn the unified resource name used to identify the object |
|
| 103 | + * @return void |
|
| 104 | + * @throws \Exception when something goes wrong, message will be logged |
|
| 105 | + */ |
|
| 106 | + public function deleteObject($urn) { |
|
| 107 | + $this->getBlobClient()->deleteBlob($this->containerName, $urn); |
|
| 108 | + } |
|
| 109 | 109 | } |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | private function getBlobClient() { |
| 60 | 60 | if (!$this->blobClient) { |
| 61 | 61 | $protocol = $this->endpoint ? substr($this->endpoint, 0, strpos($this->endpoint, ':')) : 'https'; |
| 62 | - $connectionString = "DefaultEndpointsProtocol=" . $protocol . ";AccountName=" . $this->accountName . ";AccountKey=" . $this->accountKey; |
|
| 62 | + $connectionString = "DefaultEndpointsProtocol=".$protocol.";AccountName=".$this->accountName.";AccountKey=".$this->accountKey; |
|
| 63 | 63 | if ($this->endpoint) { |
| 64 | - $connectionString .= ';BlobEndpoint=' . $this->endpoint; |
|
| 64 | + $connectionString .= ';BlobEndpoint='.$this->endpoint; |
|
| 65 | 65 | } |
| 66 | 66 | $this->blobClient = BlobRestProxy::createBlobService($connectionString); |
| 67 | 67 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @return string the container or bucket name where objects are stored |
| 77 | 77 | */ |
| 78 | 78 | public function getStorageId() { |
| 79 | - return 'azure::blob::' . $this->containerName; |
|
| 79 | + return 'azure::blob::'.$this->containerName; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |