PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/backwpup/vendor/WindowsAzure/Common/Internal/Http/HttpCallContext.php

https://gitlab.com/pankajmohale/chef2go
PHP | 446 lines | 161 code | 50 blank | 235 comment | 2 complexity | b1afd6835e3aa1e593179c0ec1beacc8 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\Common\Internal\Http
  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\Common\Internal\Http;
  24. use WindowsAzure\Common\Internal\Utilities;
  25. use WindowsAzure\Common\Internal\Resources;
  26. use WindowsAzure\Common\Internal\Validate;
  27. use WindowsAzure\Common\Internal\Http\Url;
  28. /**
  29. * Holds basic elements for making HTTP call.
  30. *
  31. * @category Microsoft
  32. * @package WindowsAzure\Common\Internal\Http
  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 HttpCallContext
  40. {
  41. /**
  42. * The HTTP method used to make this call.
  43. *
  44. * @var string
  45. */
  46. private $_method;
  47. /**
  48. * HTTP request headers.
  49. *
  50. * @var array
  51. */
  52. private $_headers;
  53. /**
  54. * The URI query parameters.
  55. *
  56. * @var array
  57. */
  58. private $_queryParams;
  59. /**
  60. * The HTTP POST parameters.
  61. *
  62. * @var array.
  63. */
  64. private $_postParameters;
  65. /**
  66. * @var string
  67. */
  68. private $_uri;
  69. /**
  70. * The URI path.
  71. *
  72. * @var string
  73. */
  74. private $_path;
  75. /**
  76. * The expected status codes.
  77. *
  78. * @var array
  79. */
  80. private $_statusCodes;
  81. /**
  82. * The HTTP request body.
  83. *
  84. * @var string
  85. */
  86. private $_body;
  87. /**
  88. * Default constructor.
  89. */
  90. public function __construct()
  91. {
  92. $this->_method = null;
  93. $this->_body = null;
  94. $this->_path = null;
  95. $this->_uri = null;
  96. $this->_queryParams = array();
  97. $this->_postParameters = array();
  98. $this->_statusCodes = array();
  99. $this->_headers = array();
  100. }
  101. /**
  102. * Gets method.
  103. *
  104. * @return string
  105. */
  106. public function getMethod()
  107. {
  108. return $this->_method;
  109. }
  110. /**
  111. * Sets method.
  112. *
  113. * @param string $method The method value.
  114. *
  115. * @return none
  116. */
  117. public function setMethod($method)
  118. {
  119. Validate::isString($method, 'method');
  120. $this->_method = $method;
  121. }
  122. /**
  123. * Gets headers.
  124. *
  125. * @return array
  126. */
  127. public function getHeaders()
  128. {
  129. return $this->_headers;
  130. }
  131. /**
  132. * Sets headers.
  133. *
  134. * Ignores the header if its value is empty.
  135. *
  136. * @param array $headers The headers value.
  137. *
  138. * @return none
  139. */
  140. public function setHeaders($headers)
  141. {
  142. $this->_headers = array();
  143. foreach ($headers as $key => $value) {
  144. $this->addHeader($key, $value);
  145. }
  146. }
  147. /**
  148. * Gets queryParams.
  149. *
  150. * @return array
  151. */
  152. public function getQueryParameters()
  153. {
  154. return $this->_queryParams;
  155. }
  156. /**
  157. * Sets queryParams.
  158. *
  159. * Ignores the query variable if its value is empty.
  160. *
  161. * @param array $queryParams The queryParams value.
  162. *
  163. * @return none
  164. */
  165. public function setQueryParameters($queryParams)
  166. {
  167. $this->_queryParams = array();
  168. foreach ($queryParams as $key => $value) {
  169. $this->addQueryParameter($key, $value);
  170. }
  171. }
  172. /**
  173. * Gets uri.
  174. *
  175. * @return string
  176. */
  177. public function getUri()
  178. {
  179. return $this->_uri;
  180. }
  181. /**
  182. * Sets uri.
  183. *
  184. * @param string $uri The uri value.
  185. *
  186. * @return none
  187. */
  188. public function setUri($uri)
  189. {
  190. Validate::isString($uri, 'uri');
  191. $this->_uri = $uri;
  192. }
  193. /**
  194. * Gets path.
  195. *
  196. * @return string
  197. */
  198. public function getPath()
  199. {
  200. return $this->_path;
  201. }
  202. /**
  203. * Sets path.
  204. *
  205. * @param string $path The path value.
  206. *
  207. * @return none
  208. */
  209. public function setPath($path)
  210. {
  211. Validate::isString($path, 'path');
  212. $this->_path = $path;
  213. }
  214. /**
  215. * Gets statusCodes.
  216. *
  217. * @return array
  218. */
  219. public function getStatusCodes()
  220. {
  221. return $this->_statusCodes;
  222. }
  223. /**
  224. * Sets statusCodes.
  225. *
  226. * @param array $statusCodes The statusCodes value.
  227. *
  228. * @return none
  229. */
  230. public function setStatusCodes($statusCodes)
  231. {
  232. $this->_statusCodes = array();
  233. foreach ($statusCodes as $value) {
  234. $this->addStatusCode($value);
  235. }
  236. }
  237. /**
  238. * Gets body.
  239. *
  240. * @return string
  241. */
  242. public function getBody()
  243. {
  244. return $this->_body;
  245. }
  246. /**
  247. * Sets body.
  248. *
  249. * @param string $body The body value.
  250. *
  251. * @return none
  252. */
  253. public function setBody($body)
  254. {
  255. Validate::isString($body, 'body');
  256. $this->_body = $body;
  257. }
  258. /**
  259. * Adds or sets header pair.
  260. *
  261. * @param string $name The HTTP header name.
  262. * @param string $value The HTTP header value.
  263. *
  264. * @return none
  265. */
  266. public function addHeader($name, $value)
  267. {
  268. Validate::isString($name, 'name');
  269. Validate::isString($value, 'value');
  270. $this->_headers[$name] = $value;
  271. }
  272. /**
  273. * Adds or sets header pair.
  274. *
  275. * Ignores header if it's value satisfies empty().
  276. *
  277. * @param string $name The HTTP header name.
  278. * @param string $value The HTTP header value.
  279. *
  280. * @return none
  281. */
  282. public function addOptionalHeader($name, $value)
  283. {
  284. Validate::isString($name, 'name');
  285. Validate::isString($value, 'value');
  286. if (!empty($value)) {
  287. $this->_headers[$name] = $value;
  288. }
  289. }
  290. /**
  291. * Removes header from the HTTP request headers.
  292. *
  293. * @param string $name The HTTP header name.
  294. *
  295. * @return none
  296. */
  297. public function removeHeader($name)
  298. {
  299. Validate::isString($name, 'name');
  300. Validate::notNullOrEmpty($name, 'name');
  301. unset($this->_headers[$name]);
  302. }
  303. /**
  304. * Adds or sets query parameter pair.
  305. *
  306. * @param string $name The URI query parameter name.
  307. * @param string $value The URI query parameter value.
  308. *
  309. * @return none
  310. */
  311. public function addQueryParameter($name, $value)
  312. {
  313. Validate::isString($name, 'name');
  314. Validate::isString($value, 'value');
  315. $this->_queryParams[$name] = $value;
  316. }
  317. /**
  318. * Gets HTTP POST parameters.
  319. *
  320. * @return array
  321. */
  322. public function getPostParameters()
  323. {
  324. return $this->_postParameters;
  325. }
  326. /**
  327. * Sets HTTP POST parameters.
  328. *
  329. * @param array $postParameters The HTTP POST parameters.
  330. *
  331. * @return none
  332. */
  333. public function setPostParameters($postParameters)
  334. {
  335. Validate::isArray($postParameters, 'postParameters');
  336. $this->_postParameters = $postParameters;
  337. }
  338. /**
  339. * Adds or sets query parameter pair.
  340. *
  341. * Ignores query parameter if it's value satisfies empty().
  342. *
  343. * @param string $name The URI query parameter name.
  344. * @param string $value The URI query parameter value.
  345. *
  346. * @return none
  347. */
  348. public function addOptionalQueryParameter($name, $value)
  349. {
  350. Validate::isString($name, 'name');
  351. Validate::isString($value, 'value');
  352. if (!empty($value)) {
  353. $this->_queryParams[$name] = $value;
  354. }
  355. }
  356. /**
  357. * Adds status code to the expected status codes.
  358. *
  359. * @param integer $statusCode The expected status code.
  360. *
  361. * @return none
  362. */
  363. public function addStatusCode($statusCode)
  364. {
  365. Validate::isInteger($statusCode, 'statusCode');
  366. $this->_statusCodes[] = $statusCode;
  367. }
  368. /**
  369. * Gets header value.
  370. *
  371. * @param string $name The header name.
  372. *
  373. * @return mix
  374. */
  375. public function getHeader($name)
  376. {
  377. return Utilities::tryGetValue($this->_headers, $name);
  378. }
  379. /**
  380. * Converts the context object to string.
  381. *
  382. * @return string
  383. */
  384. public function __toString()
  385. {
  386. $headers = Resources::EMPTY_STRING;
  387. $uri = new Url($this->_uri);
  388. $uri = $uri->getUrl();
  389. foreach ($this->_headers as $key => $value) {
  390. $headers .= "$key: $value\n";
  391. }
  392. $str = "$this->_method $uri$this->_path HTTP/1.1\n$headers\n";
  393. $str .= "$this->_body";
  394. return $str;
  395. }
  396. }