ElggCookie.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * A simple object model for an HTTP cookie
  4. *
  5. * @package Elgg.Core
  6. * @subpackage Http
  7. * @see elgg_set_cookie()
  8. * @see http://php.net/manual/en/function.setcookie.php
  9. * @see http://php.net/manual/en/function.session-set-cookie-params.php
  10. * @since 1.9.0
  11. *
  12. * @property-read string $name Name of the cookie
  13. */
  14. class ElggCookie {
  15. /** @var string */
  16. private $name;
  17. /** @var string */
  18. public $value = "";
  19. /** @var int */
  20. public $expire = 0;
  21. /** @var string */
  22. public $path = "/";
  23. /** @var string */
  24. public $domain = "";
  25. /** @var bool */
  26. public $secure = false;
  27. /** @var bool */
  28. public $httpOnly = false;
  29. /**
  30. * Constructor
  31. *
  32. * @param string $name The name of the cookie.
  33. */
  34. public function __construct($name) {
  35. $this->name = $name;
  36. }
  37. /**
  38. * Get an attribute
  39. *
  40. * @param string $name Attribute name
  41. * @return mixed
  42. */
  43. public function __get($name) {
  44. // allow reading the private name attribute
  45. if ($name === 'name') {
  46. return $this->name;
  47. }
  48. }
  49. /**
  50. * Set the time the cookie expires
  51. *
  52. * Example: $cookie->setExpiresTime("+30 days");
  53. *
  54. * @param string $time A time string appropriate for strtotime()
  55. * @return void
  56. */
  57. public function setExpiresTime($time) {
  58. $this->expire = strtotime($time);
  59. }
  60. }