PublicCookieMetadata.php 1.6 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\Cookie;
  7. /**
  8. * Class PublicCookieMetadata
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class PublicCookieMetadata extends CookieMetadata
  14. {
  15. /**
  16. * Set the number of seconds until the cookie expires
  17. *
  18. * The cookie duration can be translated into an expiration date at the time the cookie is sent.
  19. *
  20. * @param int $duration Time in seconds.
  21. * @return $this
  22. */
  23. public function setDuration($duration)
  24. {
  25. return $this->set(self::KEY_DURATION, $duration);
  26. }
  27. /**
  28. * Set the cookie duration to one year
  29. *
  30. * @return $this
  31. */
  32. public function setDurationOneYear()
  33. {
  34. return $this->setDuration(3600 * 24 * 365);
  35. }
  36. /**
  37. * Get the number of seconds until the cookie expires
  38. *
  39. * The cookie duration can be translated into an expiration date at the time the cookie is sent.
  40. *
  41. * @return int|null Time in seconds.
  42. */
  43. public function getDuration()
  44. {
  45. return $this->get(self::KEY_DURATION);
  46. }
  47. /**
  48. * Set HTTPOnly flag
  49. *
  50. * @param bool $httpOnly
  51. * @return $this
  52. */
  53. public function setHttpOnly($httpOnly)
  54. {
  55. return $this->set(self::KEY_HTTP_ONLY, $httpOnly);
  56. }
  57. /**
  58. * Set whether the cookie is only available under HTTPS
  59. *
  60. * @param bool $secure
  61. * @return $this
  62. */
  63. public function setSecure($secure)
  64. {
  65. return $this->set(self::KEY_SECURE, $secure);
  66. }
  67. }