AcsRequest.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <?php
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. /**
  21. * @deprecated See: https://github.com/aliyun/openapi-sdk-php
  22. * Class AcsRequest
  23. */
  24. abstract class AcsRequest
  25. {
  26. /**
  27. * @var string
  28. */
  29. protected $version;
  30. /**
  31. * @var string
  32. */
  33. protected $product;
  34. /**
  35. * @var string
  36. */
  37. protected $actionName;
  38. /**
  39. * @var string
  40. */
  41. protected $regionId;
  42. /**
  43. * @var string
  44. */
  45. protected $acceptFormat;
  46. /**
  47. * @var string
  48. */
  49. protected $method;
  50. /**
  51. * @var string
  52. */
  53. protected $requestScheme = 'http';
  54. /**
  55. * @var string
  56. */
  57. protected $content;
  58. /**
  59. * @var array
  60. */
  61. protected $queryParameters = array();
  62. /**
  63. * @var array
  64. */
  65. protected $headers = array();
  66. /**
  67. * @var null|string
  68. */
  69. protected $locationServiceCode;
  70. /**
  71. * @var null|string
  72. */
  73. protected $locationEndpointType;
  74. /**
  75. * @var array The original parameters of the request object.
  76. */
  77. protected $requestParameters = array();
  78. /**
  79. * @var string
  80. */
  81. protected $stringToBeSigned = '';
  82. /**
  83. * AcsRequest constructor.
  84. *
  85. * @param string $product
  86. * @param string $version
  87. * @param string $actionName
  88. * @param string|null $locationServiceCode
  89. * @param string $locationEndpointType
  90. */
  91. public function __construct($product,
  92. $version,
  93. $actionName,
  94. $locationServiceCode = null,
  95. $locationEndpointType = 'openAPI')
  96. {
  97. $this->headers['x-sdk-client'] = 'php/2.0.0';
  98. $this->product = $product;
  99. $this->version = $version;
  100. $this->actionName = $actionName;
  101. $this->locationServiceCode = $locationServiceCode;
  102. $this->locationEndpointType = $locationEndpointType;
  103. }
  104. /**
  105. * @param $iSigner
  106. * @param $credential
  107. * @param $domain
  108. *
  109. * @return mixed
  110. */
  111. abstract public function composeUrl($iSigner, $credential, $domain);
  112. /**
  113. * @return string
  114. */
  115. public function getVersion()
  116. {
  117. return $this->version;
  118. }
  119. /**
  120. * @param $version
  121. */
  122. public function setVersion($version)
  123. {
  124. $this->version = $version;
  125. }
  126. /**
  127. * @return string
  128. */
  129. public function getProduct()
  130. {
  131. return $this->product;
  132. }
  133. /**
  134. * @param string $product
  135. */
  136. public function setProduct($product)
  137. {
  138. $this->product = $product;
  139. }
  140. /**
  141. * @return string
  142. */
  143. public function getActionName()
  144. {
  145. return $this->actionName;
  146. }
  147. /**
  148. * @param string $actionName
  149. */
  150. public function setActionName($actionName)
  151. {
  152. $this->actionName = $actionName;
  153. }
  154. /**
  155. * @return string
  156. */
  157. public function getAcceptFormat()
  158. {
  159. return $this->acceptFormat;
  160. }
  161. /**
  162. * @param string $acceptFormat
  163. */
  164. public function setAcceptFormat($acceptFormat)
  165. {
  166. $this->acceptFormat = $acceptFormat;
  167. }
  168. /**
  169. * @return array
  170. */
  171. public function getQueryParameters()
  172. {
  173. return $this->queryParameters;
  174. }
  175. /**
  176. * @return array
  177. */
  178. public function getHeaders()
  179. {
  180. return $this->headers;
  181. }
  182. /**
  183. * @return string
  184. */
  185. public function getMethod()
  186. {
  187. return $this->method;
  188. }
  189. /**
  190. * @param string $method
  191. */
  192. public function setMethod($method)
  193. {
  194. $this->method = $method;
  195. }
  196. /**
  197. * @return string
  198. */
  199. public function getProtocol()
  200. {
  201. return $this->requestScheme;
  202. }
  203. /**
  204. * @param string $protocol
  205. */
  206. public function setProtocol($protocol)
  207. {
  208. $this->requestScheme = $protocol;
  209. }
  210. /**
  211. * @return string
  212. */
  213. public function getRegionId()
  214. {
  215. return $this->regionId;
  216. }
  217. /**
  218. * @param string $region
  219. */
  220. public function setRegionId($region)
  221. {
  222. $this->regionId = $region;
  223. }
  224. /**
  225. * @return string
  226. */
  227. public function getContent()
  228. {
  229. return $this->content;
  230. }
  231. /**
  232. * @param string $content
  233. */
  234. public function setContent($content)
  235. {
  236. $this->content = $content;
  237. }
  238. /**
  239. * @param string $headerKey
  240. * @param mixed $headerValue
  241. */
  242. public function addHeader($headerKey, $headerValue)
  243. {
  244. $this->headers[$headerKey] = $headerValue;
  245. }
  246. /**
  247. * @return null|string
  248. */
  249. public function getLocationServiceCode()
  250. {
  251. return $this->locationServiceCode;
  252. }
  253. /**
  254. * @return null|string
  255. */
  256. public function getLocationEndpointType()
  257. {
  258. return $this->locationEndpointType;
  259. }
  260. /**
  261. * Magic method for get parameters.
  262. *
  263. * @param string $name
  264. * @param mixed $arguments
  265. *
  266. * @return $this
  267. */
  268. public function __call($name, $arguments)
  269. {
  270. if (\strpos($name, 'get', 0) !== false) {
  271. $parameterName = $this->propertyNameByMethodName($name);
  272. return isset($this->requestParameters[$parameterName])
  273. ? $this->requestParameters[$parameterName]
  274. : null;
  275. }
  276. return $this;
  277. }
  278. /**
  279. * @param string $methodName
  280. *
  281. * @return string
  282. */
  283. protected function propertyNameByMethodName($methodName)
  284. {
  285. return \mb_strcut($methodName, 3);
  286. }
  287. /**
  288. * @return string
  289. */
  290. public function stringToBeSigned()
  291. {
  292. return $this->stringToBeSigned;
  293. }
  294. }