PageRenderTime 33ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/backwpup/vendor/WindowsAzure/Blob/Models/AccessCondition.php

https://gitlab.com/pankajmohale/chef2go
PHP | 247 lines | 74 code | 18 blank | 155 comment | 11 complexity | 5d9ed43597fd046e9a3c20c301956cfe MD5 | raw file
  1. <?php
  2. /**
  3. * LICENSE: Licensed under the Apache License, Version 2.0 (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. * http://www.apache.org/licenses/LICENSE-2.0
  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 WindowsAzure\Blob\Models
  18. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  19. * @copyright 2012 Microsoft Corporation
  20. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  21. * @link https://github.com/windowsazure/azure-sdk-for-php
  22. */
  23. namespace WindowsAzure\Blob\Models;
  24. use WindowsAzure\Common\Internal\Resources;
  25. use WindowsAzure\Common\Internal\Validate;
  26. use WindowsAzure\Common\Internal\WindowsAzureUtilities;
  27. /**
  28. * Represents a set of access conditions to be used for operations against the
  29. * storage services.
  30. *
  31. * @category Microsoft
  32. * @package WindowsAzure\Blob\Models
  33. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  34. * @copyright 2012 Microsoft Corporation
  35. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  36. * @version Release: 0.4.1_2015-03
  37. * @link https://github.com/windowsazure/azure-sdk-for-php
  38. */
  39. class AccessCondition
  40. {
  41. /**
  42. * Represents the header type.
  43. *
  44. * @var string
  45. */
  46. private $_header = Resources::EMPTY_STRING;
  47. /**
  48. * Represents the header value.
  49. *
  50. * @var string
  51. */
  52. private $_value;
  53. /**
  54. * Constructor
  55. *
  56. * @param string $headerType header name
  57. * @param string $value header value
  58. */
  59. protected function __construct($headerType, $value)
  60. {
  61. $this->setHeader($headerType);
  62. $this->setValue($value);
  63. }
  64. /**
  65. * Specifies that no access condition is set.
  66. *
  67. * @return \WindowsAzure\Blob\Models\AccessCondition
  68. */
  69. public static function none()
  70. {
  71. return new AccessCondition(Resources::EMPTY_STRING, null);
  72. }
  73. /**
  74. * Returns an access condition such that an operation will be performed only if
  75. * the resource's ETag value matches the specified ETag value.
  76. * <p>
  77. * Setting this access condition modifies the request to include the HTTP
  78. * <i>If-Match</i> conditional header. If this access condition is set, the
  79. * operation is performed only if the ETag of the resource matches the specified
  80. * ETag.
  81. * <p>
  82. * For more information, see
  83. * <a href= 'http://go.microsoft.com/fwlink/?LinkID=224642&clcid=0x409'>
  84. * Specifying Conditional Headers for Blob Service Operations</a>.
  85. *
  86. * @param string $etag a string that represents the ETag value to check.
  87. *
  88. * @return \WindowsAzure\Blob\Models\AccessCondition
  89. */
  90. public static function ifMatch($etag)
  91. {
  92. return new AccessCondition(Resources::IF_MATCH, $etag);
  93. }
  94. /**
  95. * Returns an access condition such that an operation will be performed only if
  96. * the resource has been modified since the specified time.
  97. * <p>
  98. * Setting this access condition modifies the request to include the HTTP
  99. * <i>If-Modified-Since</i> conditional header. If this access condition is set,
  100. * the operation is performed only if the resource has been modified since the
  101. * specified time.
  102. * <p>
  103. * For more information, see
  104. * <a href= 'http://go.microsoft.com/fwlink/?LinkID=224642&clcid=0x409'>
  105. * Specifying Conditional Headers for Blob Service Operations</a>.
  106. *
  107. * @param \DateTime $lastModified date that represents the last-modified
  108. * time to check for the resource.
  109. *
  110. * @return \WindowsAzure\Blob\Models\AccessCondition
  111. */
  112. public static function ifModifiedSince($lastModified)
  113. {
  114. Validate::isDate($lastModified);
  115. return new AccessCondition(
  116. Resources::IF_MODIFIED_SINCE,
  117. $lastModified
  118. );
  119. }
  120. /**
  121. * Returns an access condition such that an operation will be performed only if
  122. * the resource's ETag value does not match the specified ETag value.
  123. * <p>
  124. * Setting this access condition modifies the request to include the HTTP
  125. * <i>If-None-Match</i> conditional header. If this access condition is set, the
  126. * operation is performed only if the ETag of the resource does not match the
  127. * specified ETag.
  128. * <p>
  129. * For more information,
  130. * see <a href= 'http://go.microsoft.com/fwlink/?LinkID=224642&clcid=0x409'>
  131. * Specifying Conditional Headers for Blob Service Operations</a>.
  132. *
  133. * @param string $etag string that represents the ETag value to check.
  134. *
  135. * @return \WindowsAzure\Blob\Models\AccessCondition
  136. */
  137. public static function ifNoneMatch($etag)
  138. {
  139. return new AccessCondition(Resources::IF_NONE_MATCH, $etag);
  140. }
  141. /**
  142. * Returns an access condition such that an operation will be performed only if
  143. * the resource has not been modified since the specified time.
  144. * <p>
  145. * Setting this access condition modifies the request to include the HTTP
  146. * <i>If-Unmodified-Since</i> conditional header. If this access condition is
  147. * set, the operation is performed only if the resource has not been modified
  148. * since the specified time.
  149. * <p>
  150. * For more information, see
  151. * <a href= 'http://go.microsoft.com/fwlink/?LinkID=224642&clcid=0x409'>
  152. * Specifying Conditional Headers for Blob Service Operations</a>.
  153. *
  154. * @param \DateTime $lastModified date that represents the last-modified
  155. * time to check for the resource.
  156. *
  157. * @return \WindowsAzure\Blob\Models\AccessCondition
  158. */
  159. public static function ifNotModifiedSince($lastModified)
  160. {
  161. Validate::isDate($lastModified);
  162. return new AccessCondition(
  163. Resources::IF_UNMODIFIED_SINCE,
  164. $lastModified
  165. );
  166. }
  167. /**
  168. * Sets header type
  169. *
  170. * @param string $headerType can be one of Resources
  171. *
  172. * @return none.
  173. */
  174. public function setHeader($headerType)
  175. {
  176. $valid = AccessCondition::isValid($headerType);
  177. Validate::isTrue($valid, Resources::INVALID_HT_MSG);
  178. $this->_header = $headerType;
  179. }
  180. /**
  181. * Gets header type
  182. *
  183. * @return string.
  184. */
  185. public function getHeader()
  186. {
  187. return $this->_header;
  188. }
  189. /**
  190. * Sets the header value
  191. *
  192. * @param string $value the value to use
  193. *
  194. * @return none
  195. */
  196. public function setValue($value)
  197. {
  198. $this->_value = $value;
  199. }
  200. /**
  201. * Gets the header value
  202. *
  203. * @return string
  204. */
  205. public function getValue()
  206. {
  207. return $this->_value;
  208. }
  209. /**
  210. * Check if the $headerType belongs to valid header types
  211. *
  212. * @param string $headerType candidate header type
  213. *
  214. * @return boolean
  215. */
  216. public static function isValid($headerType)
  217. {
  218. if ( $headerType == Resources::EMPTY_STRING
  219. || $headerType == Resources::IF_UNMODIFIED_SINCE
  220. || $headerType == Resources::IF_MATCH
  221. || $headerType == Resources::IF_MODIFIED_SINCE
  222. || $headerType == Resources::IF_NONE_MATCH
  223. ) {
  224. return true;
  225. } else {
  226. return false;
  227. }
  228. }
  229. }