CookieManagerInterface.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Stdlib;
  7. use Magento\Framework\Stdlib\Cookie\CookieReaderInterface;
  8. use Magento\Framework\Stdlib\Cookie\PublicCookieMetadata;
  9. use Magento\Framework\Stdlib\Cookie\SensitiveCookieMetadata;
  10. use Magento\Framework\Stdlib\Cookie\FailureToSendException;
  11. use Magento\Framework\Stdlib\Cookie\CookieSizeLimitReachedException;
  12. use Magento\Framework\Stdlib\Cookie\CookieMetadata;
  13. use Magento\Framework\Exception\InputException;
  14. /**
  15. * CookieManager helps manage the setting, retrieving and deleting of cookies.
  16. *
  17. * The cookie manager will make it possible for an application to indicate if a cookie contains sensitive data,
  18. * this will allow extra protection to be added to the contents of the cookie as well sending directives to the browser
  19. * about how the cookie should be stored and whether JavaScript can access the cookie.
  20. *
  21. * @api
  22. * @since 100.0.2
  23. */
  24. interface CookieManagerInterface extends CookieReaderInterface
  25. {
  26. /**
  27. * Set a value in a private cookie with the given $name $value pairing.
  28. *
  29. * Sensitive cookies cannot be accessed by JS. HttpOnly will always be set to true for these cookies.
  30. *
  31. * @param string $name
  32. * @param string $value
  33. * @param SensitiveCookieMetadata $metadata
  34. * @return void
  35. * @throws FailureToSendException Cookie couldn't be sent to the browser. If this exception isn't thrown,
  36. * there is still no guarantee that the browser received and accepted the cookie.
  37. * @throws CookieSizeLimitReachedException Thrown when the cookie is too big to store any additional data.
  38. * @throws InputException If the cookie name is empty or contains invalid characters.
  39. */
  40. public function setSensitiveCookie($name, $value, SensitiveCookieMetadata $metadata = null);
  41. /**
  42. * Set a value in a public cookie with the given $name $value pairing.
  43. *
  44. * Public cookies can be accessed by JS. HttpOnly will be set to false by default for these cookies,
  45. * but can be changed to true.
  46. *
  47. * @param string $name
  48. * @param string $value
  49. * @param PublicCookieMetadata $metadata
  50. * @return void
  51. * @throws FailureToSendException If cookie couldn't be sent to the browser.
  52. * @throws CookieSizeLimitReachedException Thrown when the cookie is too big to store any additional data.
  53. * @throws InputException If the cookie name is empty or contains invalid characters.
  54. */
  55. public function setPublicCookie($name, $value, PublicCookieMetadata $metadata = null);
  56. /**
  57. * Deletes a cookie with the given name.
  58. *
  59. * @param string $name
  60. * @param CookieMetadata $metadata
  61. * @return void
  62. * @throws FailureToSendException If cookie couldn't be sent to the browser.
  63. * If this exception isn't thrown, there is still no guarantee that the browser
  64. * received and accepted the request to delete this cookie.
  65. * @throws InputException If the cookie name is empty or contains invalid characters.
  66. */
  67. public function deleteCookie($name, CookieMetadata $metadata = null);
  68. }