You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.8KB

  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\web;
  8. /**
  9. * Cookie represents information related with a cookie, such as [[name]], [[value]], [[domain]], etc.
  10. *
  11. * @author Qiang Xue <qiang.xue@gmail.com>
  12. * @since 2.0
  13. */
  14. class Cookie extends \yii\base\Object
  15. {
  16. /**
  17. * @var string name of the cookie
  18. */
  19. public $name;
  20. /**
  21. * @var string value of the cookie
  22. */
  23. public $value = '';
  24. /**
  25. * @var string domain of the cookie
  26. */
  27. public $domain = '';
  28. /**
  29. * @var integer the timestamp at which the cookie expires. This is the server timestamp.
  30. * Defaults to 0, meaning "until the browser is closed".
  31. */
  32. public $expire = 0;
  33. /**
  34. * @var string the path on the server in which the cookie will be available on. The default is '/'.
  35. */
  36. public $path = '/';
  37. /**
  38. * @var boolean whether cookie should be sent via secure connection
  39. */
  40. public $secure = false;
  41. /**
  42. * @var boolean whether the cookie should be accessible only through the HTTP protocol.
  43. * By setting this property to true, the cookie will not be accessible by scripting languages,
  44. * such as JavaScript, which can effectively help to reduce identity theft through XSS attacks.
  45. */
  46. public $httpOnly = true;
  47. /**
  48. * Magic method to turn a cookie object into a string without having to explicitly access [[value]].
  49. *
  50. * ```php
  51. * if (isset($request->cookies['name'])) {
  52. * $value = (string) $request->cookies['name'];
  53. * }
  54. * ```
  55. *
  56. * @return string The value of the cookie. If the value property is null, an empty string will be returned.
  57. */
  58. public function __toString()
  59. {
  60. return (string) $this->value;
  61. }
  62. }