-
Notifications
You must be signed in to change notification settings - Fork 0
/
CookieInterface.php
executable file
·168 lines (142 loc) · 4.18 KB
/
CookieInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Cookie;
/**
* Interface for a value object representation of an HTTP cookie.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
*/
interface CookieInterface
{
/**
* Cookies will be sent in all contexts, i.e in responses to both
* first-party and cross-origin requests. If `SameSite=None` is set,
* the cookie `Secure` attribute must also be set (or the cookie will be blocked).
*/
public const SAMESITE_NONE = 'none';
/**
* Cookies are not sent on normal cross-site subrequests (for example to
* load images or frames into a third party site), but are sent when a
* user is navigating to the origin site (i.e. when following a link).
*/
public const SAMESITE_LAX = 'lax';
/**
* Cookies will only be sent in a first-party context and not be sent
* along with requests initiated by third party websites.
*/
public const SAMESITE_STRICT = 'strict';
/**
* RFC 6265 allowed values for the "SameSite" attribute.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
*/
public const ALLOWED_SAMESITE_VALUES = [
self::SAMESITE_NONE,
self::SAMESITE_LAX,
self::SAMESITE_STRICT,
];
/**
* Expires date format.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Date
* @see https://tools.ietf.org/html/rfc7231#section-7.1.1.2
*/
public const EXPIRES_FORMAT = 'D, d-M-Y H:i:s T';
/**
* Returns a unique identifier for the cookie consisting
* of its prefixed name, path, and domain.
*/
public function getId(): string;
/**
* Gets the cookie prefix.
*/
public function getPrefix(): string;
/**
* Gets the cookie name.
*/
public function getName(): string;
/**
* Gets the cookie name prepended with the prefix, if any.
*/
public function getPrefixedName(): string;
/**
* Gets the cookie value.
*/
public function getValue(): string;
/**
* Gets the time in Unix timestamp the cookie expires.
*/
public function getExpiresTimestamp(): int;
/**
* Gets the formatted expires time.
*/
public function getExpiresString(): string;
/**
* Checks if the cookie is expired.
*/
public function isExpired(): bool;
/**
* Gets the "Max-Age" cookie attribute.
*/
public function getMaxAge(): int;
/**
* Gets the "Path" cookie attribute.
*/
public function getPath(): string;
/**
* Gets the "Domain" cookie attribute.
*/
public function getDomain(): string;
/**
* Gets the "Secure" cookie attribute.
*
* Checks if the cookie is only sent to the server when a request is made
* with the `https:` scheme (except on `localhost`), and therefore is more
* resistent to man-in-the-middle attacks.
*/
public function isSecure(): bool;
/**
* Gets the "HttpOnly" cookie attribute.
*
* Checks if JavaScript is forbidden from accessing the cookie.
*/
public function isHTTPOnly(): bool;
/**
* Gets the "SameSite" cookie attribute.
*/
public function getSameSite(): string;
/**
* Checks if the cookie should be sent with no URL encoding.
*/
public function isRaw(): bool;
/**
* Gets the options that are passable to the `setcookie` variant
* available on PHP 7.3+
*
* @return array<string, mixed>
*/
public function getOptions(): array;
/**
* Returns the Cookie as a header value.
*/
public function toHeaderString(): string;
/**
* Returns the string representation of the Cookie object.
*
* @return string
*/
public function __toString();
/**
* Returns the array representation of the Cookie object.
*
* @return array<string, mixed>
*/
public function toArray(): array;
}