暂无描述

CookieJarInterface.php 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace GuzzleHttp\Cookie;
  3. use Psr\Http\Message\RequestInterface;
  4. use Psr\Http\Message\ResponseInterface;
  5. /**
  6. * Stores HTTP cookies.
  7. *
  8. * It extracts cookies from HTTP requests, and returns them in HTTP responses.
  9. * CookieJarInterface instances automatically expire contained cookies when
  10. * necessary. Subclasses are also responsible for storing and retrieving
  11. * cookies from a file, database, etc.
  12. *
  13. * @link http://docs.python.org/2/library/cookielib.html Inspiration
  14. */
  15. interface CookieJarInterface extends \Countable, \IteratorAggregate
  16. {
  17. /**
  18. * Create a request with added cookie headers.
  19. *
  20. * If no matching cookies are found in the cookie jar, then no Cookie
  21. * header is added to the request and the same request is returned.
  22. *
  23. * @param RequestInterface $request Request object to modify.
  24. *
  25. * @return RequestInterface returns the modified request.
  26. */
  27. public function withCookieHeader(RequestInterface $request);
  28. /**
  29. * Extract cookies from an HTTP response and store them in the CookieJar.
  30. *
  31. * @param RequestInterface $request Request that was sent
  32. * @param ResponseInterface $response Response that was received
  33. */
  34. public function extractCookies(
  35. RequestInterface $request,
  36. ResponseInterface $response
  37. );
  38. /**
  39. * Sets a cookie in the cookie jar.
  40. *
  41. * @param SetCookie $cookie Cookie to set.
  42. *
  43. * @return bool Returns true on success or false on failure
  44. */
  45. public function setCookie(SetCookie $cookie);
  46. /**
  47. * Remove cookies currently held in the cookie jar.
  48. *
  49. * Invoking this method without arguments will empty the whole cookie jar.
  50. * If given a $domain argument only cookies belonging to that domain will
  51. * be removed. If given a $domain and $path argument, cookies belonging to
  52. * the specified path within that domain are removed. If given all three
  53. * arguments, then the cookie with the specified name, path and domain is
  54. * removed.
  55. *
  56. * @param string $domain Clears cookies matching a domain
  57. * @param string $path Clears cookies matching a domain and path
  58. * @param string $name Clears cookies matching a domain, path, and name
  59. *
  60. * @return CookieJarInterface
  61. */
  62. public function clear($domain = null, $path = null, $name = null);
  63. /**
  64. * Discard all sessions cookies.
  65. *
  66. * Removes cookies that don't have an expire field or a have a discard
  67. * field set to true. To be called when the user agent shuts down according
  68. * to RFC 2965.
  69. */
  70. public function clearSessionCookies();
  71. /**
  72. * Converts the cookie jar to an array.
  73. *
  74. * @return array
  75. */
  76. public function toArray();
  77. }