MicrosoftAzureStorageCommonServicesBuilder

Builds azure service objects.

Defined (1)

The class is defined in the following location(s).

/lib/Azure/MicrosoftAzureStorage/Common/ServicesBuilder.php  
  1. class ServicesBuilder 
  2. /** 
  3. * @var ServicesBuilder 
  4. */ 
  5. private static $_instance = null; 
  6.  
  7. /** 
  8. * Gets the serializer used in the REST services construction. 
  9. * @return MicrosoftAzure\Storage\Common\Internal\Serialization\ISerializer 
  10. */ 
  11. protected function serializer() 
  12. return new XmlSerializer(); 
  13.  
  14. /** 
  15. * Gets the MIME serializer used in the REST services construction. 
  16. * @return \MicrosoftAzure\Storage\Table\Internal\IMimeReaderWriter 
  17. */ 
  18. protected function mimeSerializer() 
  19. return new MimeReaderWriter(); 
  20.  
  21. /** 
  22. * Gets the Atom serializer used in the REST services construction. 
  23. * @return \MicrosoftAzure\Storage\Table\Internal\IAtomReaderWriter 
  24. */ 
  25. protected function atomSerializer() 
  26. return new AtomReaderWriter(); 
  27.  
  28. /** 
  29. * Gets the Queue authentication scheme. 
  30. * @param string $accountName The account name. 
  31. * @param string $accountKey The account key. 
  32. * @return \MicrosoftAzure\Storage\Common\Internal\Authentication\StorageAuthScheme 
  33. */ 
  34. protected function queueAuthenticationScheme($accountName, $accountKey) 
  35. return new SharedKeyAuthScheme($accountName, $accountKey); 
  36.  
  37. /** 
  38. * Gets the Blob authentication scheme. 
  39. * @param string $accountName The account name. 
  40. * @param string $accountKey The account key. 
  41. * @return \MicrosoftAzure\Storage\Common\Internal\Authentication\StorageAuthScheme 
  42. */ 
  43. protected function blobAuthenticationScheme($accountName, $accountKey) 
  44. return new SharedKeyAuthScheme($accountName, $accountKey); 
  45.  
  46. /** 
  47. * Gets the Table authentication scheme. 
  48. * @param string $accountName The account name. 
  49. * @param string $accountKey The account key. 
  50. * @return TableSharedKeyLiteAuthScheme 
  51. */ 
  52. protected function tableAuthenticationScheme($accountName, $accountKey) 
  53. return new TableSharedKeyLiteAuthScheme($accountName, $accountKey); 
  54.  
  55. /** 
  56. * Builds a queue object. 
  57. * @param string $connectionString The configuration connection string. 
  58. * @param array $options Array of options to pass to the service 
  59. * @return \MicrosoftAzure\Storage\Queue\Internal\IQueue 
  60. */ 
  61. public function createQueueService($connectionString, $options = []) 
  62. $settings = StorageServiceSettings::createFromConnectionString( 
  63. $connectionString 
  64. ); 
  65.  
  66. $serializer = $this->serializer(); 
  67. $uri = Utilities::tryAddUrlScheme( 
  68. $settings->getQueueEndpointUri() 
  69. ); 
  70.  
  71. $queueWrapper = new QueueRestProxy( 
  72. $uri,  
  73. $settings->getName(),  
  74. $serializer,  
  75. $options 
  76. ); 
  77.  
  78. // Adding headers filter 
  79. $headers = array( 
  80. Resources::USER_AGENT => self::getUserAgent(),  
  81. ); 
  82.  
  83. $headers[Resources::X_MS_VERSION] = Resources::STORAGE_API_LATEST_VERSION; 
  84.  
  85. $headersFilter = new HeadersFilter($headers); 
  86. $queueWrapper = $queueWrapper->withFilter($headersFilter); 
  87.  
  88. // Adding date filter 
  89. $dateFilter = new DateFilter(); 
  90. $queueWrapper = $queueWrapper->withFilter($dateFilter); 
  91.  
  92. // Adding authentication filter 
  93. $authFilter = new AuthenticationFilter( 
  94. $this->queueAuthenticationScheme( 
  95. $settings->getName(),  
  96. $settings->getKey() 
  97. ); 
  98.  
  99. $queueWrapper = $queueWrapper->withFilter($authFilter); 
  100.  
  101. return $queueWrapper; 
  102.  
  103. /** 
  104. * Builds a blob object. 
  105. * @param string $connectionString The configuration connection string. 
  106. * @param array $options Array of options to pass to the service 
  107. * @return \MicrosoftAzure\Storage\Blob\Internal\IBlob 
  108. */ 
  109. public function createBlobService($connectionString, $options = []) 
  110. $settings = StorageServiceSettings::createFromConnectionString( 
  111. $connectionString 
  112. ); 
  113.  
  114. $serializer = $this->serializer(); 
  115. $uri = Utilities::tryAddUrlScheme( 
  116. $settings->getBlobEndpointUri() 
  117. ); 
  118.  
  119. $blobWrapper = new BlobRestProxy( 
  120. $uri,  
  121. $settings->getName(),  
  122. $serializer,  
  123. $options 
  124. ); 
  125.  
  126. // Adding headers filter 
  127. $headers = array( 
  128. Resources::USER_AGENT => self::getUserAgent(),  
  129. ); 
  130.  
  131. $headers[Resources::X_MS_VERSION] = Resources::STORAGE_API_LATEST_VERSION; 
  132.  
  133. $headersFilter = new HeadersFilter($headers); 
  134. $blobWrapper = $blobWrapper->withFilter($headersFilter); 
  135.  
  136. // Adding date filter 
  137. $dateFilter = new DateFilter(); 
  138. $blobWrapper = $blobWrapper->withFilter($dateFilter); 
  139.  
  140. $authFilter = new AuthenticationFilter( 
  141. $this->blobAuthenticationScheme( 
  142. $settings->getName(),  
  143. $settings->getKey() 
  144. ); 
  145.  
  146. $blobWrapper = $blobWrapper->withFilter($authFilter); 
  147.  
  148. return $blobWrapper; 
  149.  
  150. /** 
  151. * Builds a table object. 
  152. * @param string $connectionString The configuration connection string. 
  153. * @param array $options Array of options to pass to the service 
  154. * @return \MicrosoftAzure\Storage\Table\Internal\ITable 
  155. */ 
  156. public function createTableService($connectionString, $options = []) 
  157. $settings = StorageServiceSettings::createFromConnectionString( 
  158. $connectionString 
  159. ); 
  160.  
  161. $atomSerializer = $this->atomSerializer(); 
  162. $mimeSerializer = $this->mimeSerializer(); 
  163. $serializer = $this->serializer(); 
  164. $uri = Utilities::tryAddUrlScheme( 
  165. $settings->getTableEndpointUri() 
  166. ); 
  167.  
  168. $tableWrapper = new TableRestProxy( 
  169. $uri,  
  170. $atomSerializer,  
  171. $mimeSerializer,  
  172. $serializer,  
  173. $options 
  174. ); 
  175.  
  176. // Adding headers filter 
  177. $headers = array(); 
  178. $latestServicesVersion = Resources::STORAGE_API_LATEST_VERSION; 
  179. $currentVersion = Resources::DATA_SERVICE_VERSION_VALUE; 
  180. $maxVersion = Resources::MAX_DATA_SERVICE_VERSION_VALUE; 
  181. $accept = Resources::ACCEPT_HEADER_VALUE; 
  182. $acceptCharset = Resources::ACCEPT_CHARSET_VALUE; 
  183. $userAgent = self::getUserAgent(); 
  184.  
  185. $headers[Resources::X_MS_VERSION] = $latestServicesVersion; 
  186. $headers[Resources::DATA_SERVICE_VERSION] = $currentVersion; 
  187. $headers[Resources::MAX_DATA_SERVICE_VERSION] = $maxVersion; 
  188. $headers[Resources::MAX_DATA_SERVICE_VERSION] = $maxVersion; 
  189. $headers[Resources::ACCEPT_HEADER] = $accept; 
  190. $headers[Resources::ACCEPT_CHARSET] = $acceptCharset; 
  191. $headers[Resources::USER_AGENT] = $userAgent; 
  192.  
  193. $headersFilter = new HeadersFilter($headers); 
  194. $tableWrapper = $tableWrapper->withFilter($headersFilter); 
  195.  
  196. // Adding date filter 
  197. $dateFilter = new DateFilter(); 
  198. $tableWrapper = $tableWrapper->withFilter($dateFilter); 
  199.  
  200. // Adding authentication filter 
  201. $authFilter = new AuthenticationFilter( 
  202. $this->tableAuthenticationScheme( 
  203. $settings->getName(),  
  204. $settings->getKey() 
  205. ); 
  206.  
  207. $tableWrapper = $tableWrapper->withFilter($authFilter); 
  208.  
  209. return $tableWrapper; 
  210.  
  211. /** 
  212. * Gets the user agent string used in request header. 
  213. * @return string 
  214. */ 
  215. private static function getUserAgent() 
  216. // e.g. User-Agent: Azure-Storage/0.10.0 (PHP 5.5.32) 
  217. return 'Azure-Storage/' . Resources::SDK_VERSION . ' (PHP ' . PHP_VERSION . ')'; 
  218.  
  219. /** 
  220. * Gets the static instance of this class. 
  221. * @return ServicesBuilder 
  222. */ 
  223. public static function getInstance() 
  224. if (!isset(self::$_instance)) { 
  225. self::$_instance = new ServicesBuilder(); 
  226.  
  227. return self::$_instance;