ClientInterface.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. namespace Guzzle\Http;
  3. use Guzzle\Common\HasDispatcherInterface;
  4. use Guzzle\Common\Collection;
  5. use Guzzle\Common\Exception\InvalidArgumentException;
  6. use Guzzle\Http\Message\EntityEnclosingRequestInterface;
  7. use Guzzle\Http\Message\RequestInterface;
  8. /**
  9. * Client interface for send HTTP requests
  10. */
  11. interface ClientInterface extends HasDispatcherInterface
  12. {
  13. const CREATE_REQUEST = 'client.create_request';
  14. /** @var string RFC 1123 HTTP-Date */
  15. const HTTP_DATE = 'D, d M Y H:i:s \G\M\T';
  16. /**
  17. * Set the configuration object to use with the client
  18. *
  19. * @param array|Collection $config Parameters that define how the client behaves
  20. *
  21. * @return self
  22. */
  23. public function setConfig($config);
  24. /**
  25. * Get a configuration setting or all of the configuration settings. The Collection result of this method can be
  26. * modified to change the configuration settings of a client.
  27. *
  28. * A client should honor the following special values:
  29. *
  30. * - request.options: Associative array of default RequestFactory options to apply to each request
  31. * - request.params: Associative array of request parameters (data values) to apply to each request
  32. * - curl.options: Associative array of cURL configuration settings to apply to each request
  33. * - ssl.certificate_authority: Path a CAINFO, CAPATH, true to use strict defaults, or false to disable verification
  34. * - redirect.disable: Set to true to disable redirects
  35. *
  36. * @param bool|string $key Configuration value to retrieve. Set to FALSE to retrieve all values of the client.
  37. * The object return can be modified, and modifications will affect the client's config.
  38. * @return mixed|Collection
  39. * @see \Guzzle\Http\Message\RequestFactoryInterface::applyOptions for a full list of request.options options
  40. */
  41. public function getConfig($key = false);
  42. /**
  43. * Create and return a new {@see RequestInterface} configured for the client.
  44. *
  45. * Use an absolute path to override the base path of the client, or a relative path to append to the base path of
  46. * the client. The URI can contain the query string as well. Use an array to provide a URI template and additional
  47. * variables to use in the URI template expansion.
  48. *
  49. * @param string $method HTTP method. Defaults to GET
  50. * @param string|array $uri Resource URI.
  51. * @param array|Collection $headers HTTP headers
  52. * @param string|resource|array|EntityBodyInterface $body Entity body of request (POST/PUT) or response (GET)
  53. * @param array $options Array of options to apply to the request
  54. *
  55. * @return RequestInterface
  56. * @throws InvalidArgumentException if a URI array is passed that does not contain exactly two elements: the URI
  57. * followed by template variables
  58. */
  59. public function createRequest(
  60. $method = RequestInterface::GET,
  61. $uri = null,
  62. $headers = null,
  63. $body = null,
  64. array $options = array()
  65. );
  66. /**
  67. * Create a GET request for the client
  68. *
  69. * @param string|array $uri Resource URI
  70. * @param array|Collection $headers HTTP headers
  71. * @param array $options Options to apply to the request. For BC compatibility, you can also pass a
  72. * string to tell Guzzle to download the body of the response to a particular
  73. * location. Use the 'body' option instead for forward compatibility.
  74. * @return RequestInterface
  75. * @see Guzzle\Http\ClientInterface::createRequest()
  76. */
  77. public function get($uri = null, $headers = null, $options = array());
  78. /**
  79. * Create a HEAD request for the client
  80. *
  81. * @param string|array $uri Resource URI
  82. * @param array|Collection $headers HTTP headers
  83. * @param array $options Options to apply to the request
  84. *
  85. * @return RequestInterface
  86. * @see Guzzle\Http\ClientInterface::createRequest()
  87. */
  88. public function head($uri = null, $headers = null, array $options = array());
  89. /**
  90. * Create a DELETE request for the client
  91. *
  92. * @param string|array $uri Resource URI
  93. * @param array|Collection $headers HTTP headers
  94. * @param string|resource|EntityBodyInterface $body Body to send in the request
  95. * @param array $options Options to apply to the request
  96. *
  97. * @return EntityEnclosingRequestInterface
  98. * @see Guzzle\Http\ClientInterface::createRequest()
  99. */
  100. public function delete($uri = null, $headers = null, $body = null, array $options = array());
  101. /**
  102. * Create a PUT request for the client
  103. *
  104. * @param string|array $uri Resource URI
  105. * @param array|Collection $headers HTTP headers
  106. * @param string|resource|EntityBodyInterface $body Body to send in the request
  107. * @param array $options Options to apply to the request
  108. *
  109. * @return EntityEnclosingRequestInterface
  110. * @see Guzzle\Http\ClientInterface::createRequest()
  111. */
  112. public function put($uri = null, $headers = null, $body = null, array $options = array());
  113. /**
  114. * Create a PATCH request for the client
  115. *
  116. * @param string|array $uri Resource URI
  117. * @param array|Collection $headers HTTP headers
  118. * @param string|resource|EntityBodyInterface $body Body to send in the request
  119. * @param array $options Options to apply to the request
  120. *
  121. * @return EntityEnclosingRequestInterface
  122. * @see Guzzle\Http\ClientInterface::createRequest()
  123. */
  124. public function patch($uri = null, $headers = null, $body = null, array $options = array());
  125. /**
  126. * Create a POST request for the client
  127. *
  128. * @param string|array $uri Resource URI
  129. * @param array|Collection $headers HTTP headers
  130. * @param array|Collection|string|EntityBodyInterface $postBody POST body. Can be a string, EntityBody, or
  131. * associative array of POST fields to send in the body of the
  132. * request. Prefix a value in the array with the @ symbol to
  133. * reference a file.
  134. * @param array $options Options to apply to the request
  135. *
  136. * @return EntityEnclosingRequestInterface
  137. * @see Guzzle\Http\ClientInterface::createRequest()
  138. */
  139. public function post($uri = null, $headers = null, $postBody = null, array $options = array());
  140. /**
  141. * Create an OPTIONS request for the client
  142. *
  143. * @param string|array $uri Resource URI
  144. * @param array $options Options to apply to the request
  145. *
  146. * @return RequestInterface
  147. * @see Guzzle\Http\ClientInterface::createRequest()
  148. */
  149. public function options($uri = null, array $options = array());
  150. /**
  151. * Sends a single request or an array of requests in parallel
  152. *
  153. * @param array|RequestInterface $requests One or more RequestInterface objects to send
  154. *
  155. * @return \Guzzle\Http\Message\Response|array Returns a single Response or an array of Response objects
  156. */
  157. public function send($requests);
  158. /**
  159. * Get the client's base URL as either an expanded or raw URI template
  160. *
  161. * @param bool $expand Set to FALSE to get the raw base URL without URI template expansion
  162. *
  163. * @return string|null
  164. */
  165. public function getBaseUrl($expand = true);
  166. /**
  167. * Set the base URL of the client
  168. *
  169. * @param string $url The base service endpoint URL of the webservice
  170. *
  171. * @return self
  172. */
  173. public function setBaseUrl($url);
  174. /**
  175. * Set the User-Agent header to be used on all requests from the client
  176. *
  177. * @param string $userAgent User agent string
  178. * @param bool $includeDefault Set to true to prepend the value to Guzzle's default user agent string
  179. *
  180. * @return self
  181. */
  182. public function setUserAgent($userAgent, $includeDefault = false);
  183. /**
  184. * Set SSL verification options.
  185. *
  186. * Setting $certificateAuthority to TRUE will result in the bundled cacert.pem being used to verify against the
  187. * remote host.
  188. *
  189. * Alternate certificates to verify against can be specified with the $certificateAuthority option set to the full
  190. * path to a certificate file, or the path to a directory containing certificates.
  191. *
  192. * Setting $certificateAuthority to FALSE will turn off peer verification, unset the bundled cacert.pem, and
  193. * disable host verification. Please don't do this unless you really know what you're doing, and why you're doing
  194. * it.
  195. *
  196. * @param string|bool $certificateAuthority bool, file path, or directory path
  197. * @param bool $verifyPeer FALSE to stop from verifying the peer's certificate.
  198. * @param int $verifyHost Set to 1 to check the existence of a common name in the SSL peer
  199. * certificate. 2 to check the existence of a common name and also verify
  200. * that it matches the hostname provided.
  201. * @return self
  202. */
  203. public function setSslVerification($certificateAuthority = true, $verifyPeer = true, $verifyHost = 2);
  204. }