/azure-storage-blob/src/Blob/Models/AppendBlockResult.php

https://github.com/Azure/azure-storage-php · PHP · 244 lines · 106 code · 25 blank · 113 comment · 1 complexity · fd7a5afda85dae5e753ad01e2fed985c MD5 · raw file

  1. <?php
  2. /**
  3. * LICENSE: The MIT License (the "License")
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. * https://github.com/azure/azure-storage-php/LICENSE
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. *
  14. * PHP version 5
  15. *
  16. * @category Microsoft
  17. * @package MicrosoftAzure\Storage\Blob\Models
  18. * @author Azure Storage PHP SDK <dmsh@microsoft.com>
  19. * @copyright 2017 Microsoft Corporation
  20. * @license https://github.com/azure/azure-storage-php/LICENSE
  21. * @link https://github.com/azure/azure-storage-php
  22. */
  23. namespace MicrosoftAzure\Storage\Blob\Models;
  24. use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources;
  25. use MicrosoftAzure\Storage\Common\Internal\Utilities;
  26. /**
  27. * The result of calling appendBlock API.
  28. *
  29. * @category Microsoft
  30. * @package MicrosoftAzure\Storage\Blob\Models
  31. * @author Azure Storage PHP SDK <dmsh@microsoft.com>
  32. * @copyright 2016 Microsoft Corporation
  33. * @license https://github.com/azure/azure-storage-php/LICENSE
  34. * @link https://github.com/azure/azure-storage-php
  35. */
  36. class AppendBlockResult
  37. {
  38. private $appendOffset;
  39. private $committedBlockCount;
  40. private $contentMD5;
  41. private $etag;
  42. private $lastModified;
  43. private $requestServerEncrypted;
  44. /**
  45. * Creates AppendBlockResult object from the response of the put block request.
  46. *
  47. * @param array $headers The HTTP response headers in array representation.
  48. *
  49. * @internal
  50. *
  51. * @return AppendBlockResult
  52. */
  53. public static function create(array $headers)
  54. {
  55. $result = new AppendBlockResult();
  56. $result->setAppendOffset(
  57. intval(
  58. Utilities::tryGetValueInsensitive(
  59. Resources::X_MS_BLOB_APPEND_OFFSET, $headers
  60. )
  61. )
  62. );
  63. $result->setCommittedBlockCount(
  64. intval(
  65. Utilities::tryGetValueInsensitive(
  66. Resources::X_MS_BLOB_COMMITTED_BLOCK_COUNT, $headers
  67. )
  68. )
  69. );
  70. $result->setContentMD5(
  71. Utilities::tryGetValueInsensitive(Resources::CONTENT_MD5, $headers)
  72. );
  73. $result->setEtag(
  74. Utilities::tryGetValueInsensitive(Resources::ETAG, $headers)
  75. );
  76. if (Utilities::arrayKeyExistsInsensitive(
  77. Resources::LAST_MODIFIED,
  78. $headers
  79. )) {
  80. $lastModified = Utilities::tryGetValueInsensitive(
  81. Resources::LAST_MODIFIED,
  82. $headers
  83. );
  84. $lastModified = Utilities::rfc1123ToDateTime($lastModified);
  85. $result->setLastModified($lastModified);
  86. }
  87. $result->setRequestServerEncrypted(
  88. Utilities::toBoolean(
  89. Utilities::tryGetValueInsensitive(
  90. Resources::X_MS_REQUEST_SERVER_ENCRYPTED,
  91. $headers
  92. ),
  93. true
  94. )
  95. );
  96. return $result;
  97. }
  98. /**
  99. * Gets Etag of the blob that the client can use to perform conditional
  100. * PUT operations by using the If-Match request header.
  101. *
  102. * @return string
  103. */
  104. public function getEtag()
  105. {
  106. return $this->etag;
  107. }
  108. /**
  109. * Sets the etag value.
  110. *
  111. * @param string $etag etag as a string.
  112. *
  113. * @return void
  114. */
  115. protected function setEtag($etag)
  116. {
  117. $this->etag = $etag;
  118. }
  119. /**
  120. * Gets $lastModified value.
  121. *
  122. * @return \DateTime
  123. */
  124. public function getLastModified()
  125. {
  126. return $this->lastModified;
  127. }
  128. /**
  129. * Sets the $lastModified value.
  130. *
  131. * @param \DateTime $lastModified $lastModified value.
  132. *
  133. * @return void
  134. */
  135. protected function setLastModified($lastModified)
  136. {
  137. $this->lastModified = $lastModified;
  138. }
  139. /**
  140. * Gets block content MD5.
  141. *
  142. * @return string
  143. */
  144. public function getContentMD5()
  145. {
  146. return $this->contentMD5;
  147. }
  148. /**
  149. * Sets the content MD5 value.
  150. *
  151. * @param string $contentMD5 conent MD5 as a string.
  152. *
  153. * @return void
  154. */
  155. protected function setContentMD5($contentMD5)
  156. {
  157. $this->contentMD5 = $contentMD5;
  158. }
  159. /**
  160. * Gets the offset at which the block was committed, in bytes.
  161. *
  162. * @return int
  163. */
  164. public function getAppendOffset()
  165. {
  166. return $this->appendOffset;
  167. }
  168. /**
  169. * Sets the offset at which the block was committed, in bytes.
  170. *
  171. * @param int $appendOffset append offset, in bytes.
  172. *
  173. * @return void
  174. */
  175. protected function setAppendOffset($appendOffset)
  176. {
  177. $this->appendOffset = $appendOffset;
  178. }
  179. /**
  180. * Gets the number of committed blocks present in the blob.
  181. *
  182. * @return int
  183. */
  184. public function getCommittedBlockCount()
  185. {
  186. return $this->committedBlockCount;
  187. }
  188. /**
  189. * Sets the number of committed blocks present in the blob.
  190. *
  191. * @param int $committedBlockCount the number of committed blocks present in the blob.
  192. *
  193. * @return void
  194. */
  195. protected function setCommittedBlockCount($committedBlockCount)
  196. {
  197. $this->committedBlockCount = $committedBlockCount;
  198. }
  199. /**
  200. * Gets the whether the contents of the request are successfully encrypted.
  201. *
  202. * @return boolean
  203. */
  204. public function getRequestServerEncrypted()
  205. {
  206. return $this->requestServerEncrypted;
  207. }
  208. /**
  209. * Sets the request server encryption value.
  210. *
  211. * @param boolean $requestServerEncrypted
  212. *
  213. * @return void
  214. */
  215. public function setRequestServerEncrypted($requestServerEncrypted)
  216. {
  217. $this->requestServerEncrypted = $requestServerEncrypted;
  218. }
  219. }