Permalink
Browse files

建立 Container

  • Loading branch information...
1 parent 325d35d commit 10905247074a251dc711573af1287b11310a72f0 Sam.IO.Hsiao committed Aug 14, 2016
Showing with 41 additions and 0 deletions.
  1. +41 −0 app/Services/AzureBlobService.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace App\Services;
+
+use MicrosoftAzure\Storage\Blob\Internal\IBlob;
+use MicrosoftAzure\Storage\Common\ServiceException;
+use WindowsAzure\Common\ServicesBuilder;
+
+class AzureBlobService
+{
+ /** @var string */
+ protected $storageConnectionString;
+ /** @var IBlob */
+ protected $blobProxy;
+
+ /**
+ * AzureBlobService constructor.
+ */
+ public function __construct()
+ {
+ $this->storageConnectionString = env('AZURE_STORAGE');
+ $this->blobProxy = ServicesBuilder::getInstance()->createBlobService($this->storageConnectionString);
+ }
+
+ /**
+ * 建立 Container
+ * @param string $containerName
+ * @return bool
+ */
+ public function createContainer(string $containerName) : bool
+ {
+ try {
+ $this->blobProxy->createContainer($containerName);
+ } catch (ServiceException $exception) {
+ echo $exception->getCode() . ':' . $exception->getMessage();
+ return false;
+ }
+
+ return true;
+ }
+}

0 comments on commit 1090524

Please sign in to comment.