PageRenderTime 10542ms CodeModel.GetById 40ms RepoModel.GetById 7ms app.codeStats 0ms

/public/packages/ckeditor/plugins/ckfinder/core/connector/php/vendor/microsoft/azure-storage/src/Common/Internal/ServiceRestTrait.php

https://bitbucket.org/AndreFigueira93/siscon-laravel
PHP | 259 lines | 141 code | 23 blank | 95 comment | 3 complexity | d9db9b412ed3902a9bb1bb9911bb5a98 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, MPL-2.0-no-copyleft-exception
  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. * @ignore
  17. * @category Microsoft
  18. * @package MicrosoftAzure\Storage\Common\Internal
  19. * @author Azure Storage PHP SDK <dmsh@microsoft.com>
  20. * @copyright 2017 Microsoft Corporation
  21. * @license https://github.com/azure/azure-storage-php/LICENSE
  22. * @link https://github.com/azure/azure-storage-php
  23. */
  24. namespace MicrosoftAzure\Storage\Common\Internal;
  25. use MicrosoftAzure\Storage\Common\LocationMode;
  26. use MicrosoftAzure\Storage\Common\Models\ServiceOptions;
  27. use MicrosoftAzure\Storage\Common\Models\ServiceProperties;
  28. use MicrosoftAzure\Storage\Common\Models\GetServicePropertiesResult;
  29. use MicrosoftAzure\Storage\Common\Models\GetServiceStatsResult;
  30. /**
  31. * Trait implementing common REST API for all the services, including the
  32. * following:
  33. * Get/Set Service Properties
  34. * Get service stats
  35. *
  36. * @category Microsoft
  37. * @package MicrosoftAzure\Storage\Common\Internal
  38. * @author Azure Storage PHP SDK <dmsh@microsoft.com>
  39. * @copyright 2017 Microsoft Corporation
  40. * @license https://github.com/azure/azure-storage-php/LICENSE
  41. * @link https://github.com/azure/azure-storage-php
  42. */
  43. trait ServiceRestTrait
  44. {
  45. /**
  46. * Gets the properties of the service.
  47. *
  48. * @param ServiceOptions $options The optional parameters.
  49. *
  50. * @return \MicrosoftAzure\Storage\Common\Models\GetServicePropertiesResult
  51. *
  52. * @see http://msdn.microsoft.com/en-us/library/windowsazure/hh452239.aspx
  53. */
  54. public function getServiceProperties(
  55. ServiceOptions $options = null
  56. ) {
  57. return $this->getServicePropertiesAsync($options)->wait();
  58. }
  59. /**
  60. * Creates promise to get the properties of the service.
  61. *
  62. * @param ServiceOptions $options The optional parameters.
  63. *
  64. * @return \GuzzleHttp\Promise\PromiseInterface
  65. *
  66. * @see http://msdn.microsoft.com/en-us/library/windowsazure/hh452239.aspx
  67. */
  68. public function getServicePropertiesAsync(
  69. ServiceOptions $options = null
  70. ) {
  71. $method = Resources::HTTP_GET;
  72. $headers = array();
  73. $queryParams = array();
  74. $postParams = array();
  75. $path = Resources::EMPTY_STRING;
  76. if (is_null($options)) {
  77. $options = new ServiceOptions();
  78. }
  79. $this->addOptionalQueryParam(
  80. $queryParams,
  81. Resources::QP_REST_TYPE,
  82. 'service'
  83. );
  84. $this->addOptionalQueryParam(
  85. $queryParams,
  86. Resources::QP_COMP,
  87. 'properties'
  88. );
  89. $dataSerializer = $this->dataSerializer;
  90. return $this->sendAsync(
  91. $method,
  92. $headers,
  93. $queryParams,
  94. $postParams,
  95. $path,
  96. Resources::STATUS_OK,
  97. Resources::EMPTY_STRING,
  98. $options
  99. )->then(function ($response) use ($dataSerializer) {
  100. $parsed = $dataSerializer->unserialize($response->getBody());
  101. return GetServicePropertiesResult::create($parsed);
  102. }, null);
  103. }
  104. /**
  105. * Sets the properties of the service.
  106. *
  107. * It's recommended to use getServiceProperties, alter the returned object and
  108. * then use setServiceProperties with this altered object.
  109. *
  110. * @param ServiceProperties $serviceProperties The service properties.
  111. * @param ServiceOptions $options The optional parameters.
  112. *
  113. * @return void
  114. *
  115. * @see http://msdn.microsoft.com/en-us/library/windowsazure/hh452235.aspx
  116. */
  117. public function setServiceProperties(
  118. ServiceProperties $serviceProperties,
  119. ServiceOptions $options = null
  120. ) {
  121. $this->setServicePropertiesAsync($serviceProperties, $options)->wait();
  122. }
  123. /**
  124. * Creates the promise to set the properties of the service.
  125. *
  126. * It's recommended to use getServiceProperties, alter the returned object and
  127. * then use setServiceProperties with this altered object.
  128. *
  129. * @param ServiceProperties $serviceProperties The service properties.
  130. * @param ServiceOptions $options The optional parameters.
  131. *
  132. * @return \GuzzleHttp\Promise\PromiseInterface
  133. *
  134. * @see http://msdn.microsoft.com/en-us/library/windowsazure/hh452235.aspx
  135. */
  136. public function setServicePropertiesAsync(
  137. ServiceProperties $serviceProperties,
  138. ServiceOptions $options = null
  139. ) {
  140. Validate::isTrue(
  141. $serviceProperties instanceof ServiceProperties,
  142. Resources::INVALID_SVC_PROP_MSG
  143. );
  144. $method = Resources::HTTP_PUT;
  145. $headers = array();
  146. $queryParams = array();
  147. $postParams = array();
  148. $path = Resources::EMPTY_STRING;
  149. $body = $serviceProperties->toXml($this->dataSerializer);
  150. if (is_null($options)) {
  151. $options = new ServiceOptions();
  152. }
  153. $this->addOptionalQueryParam(
  154. $queryParams,
  155. Resources::QP_REST_TYPE,
  156. 'service'
  157. );
  158. $this->addOptionalQueryParam(
  159. $queryParams,
  160. Resources::QP_COMP,
  161. 'properties'
  162. );
  163. $this->addOptionalHeader(
  164. $headers,
  165. Resources::CONTENT_TYPE,
  166. Resources::URL_ENCODED_CONTENT_TYPE
  167. );
  168. $options->setLocationMode(LocationMode::PRIMARY_ONLY);
  169. return $this->sendAsync(
  170. $method,
  171. $headers,
  172. $queryParams,
  173. $postParams,
  174. $path,
  175. Resources::STATUS_ACCEPTED,
  176. $body,
  177. $options
  178. );
  179. }
  180. /**
  181. * Retrieves statistics related to replication for the service. The operation
  182. * will only be sent to secondary location endpoint.
  183. *
  184. * @param ServiceOptions|null $options The options this operation sends with.
  185. *
  186. * @return GetServiceStatsResult
  187. */
  188. public function getServiceStats(ServiceOptions $options = null)
  189. {
  190. return $this->getServiceStatsAsync($options)->wait();
  191. }
  192. /**
  193. * Creates promise that retrieves statistics related to replication for the
  194. * service. The operation will only be sent to secondary location endpoint.
  195. *
  196. * @param ServiceOptions|null $options The options this operation sends with.
  197. *
  198. * @return \GuzzleHttp\Promise\PromiseInterface
  199. */
  200. public function getServiceStatsAsync(ServiceOptions $options = null)
  201. {
  202. $method = Resources::HTTP_GET;
  203. $headers = array();
  204. $queryParams = array();
  205. $postParams = array();
  206. $path = Resources::EMPTY_STRING;
  207. if (is_null($options)) {
  208. $options = new ServiceOptions();
  209. }
  210. $this->addOptionalQueryParam(
  211. $queryParams,
  212. Resources::QP_REST_TYPE,
  213. 'service'
  214. );
  215. $this->addOptionalQueryParam(
  216. $queryParams,
  217. Resources::QP_COMP,
  218. 'stats'
  219. );
  220. $dataSerializer = $this->dataSerializer;
  221. $options->setLocationMode(LocationMode::SECONDARY_ONLY);
  222. return $this->sendAsync(
  223. $method,
  224. $headers,
  225. $queryParams,
  226. $postParams,
  227. $path,
  228. Resources::STATUS_OK,
  229. Resources::EMPTY_STRING,
  230. $options
  231. )->then(function ($response) use ($dataSerializer) {
  232. $parsed = $dataSerializer->unserialize($response->getBody());
  233. return GetServiceStatsResult::create($parsed);
  234. }, null);
  235. }
  236. }