CookieJarInterface.php 2.9 KB

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