File tree Expand file tree Collapse file tree 1 file changed +23
-8
lines changed Expand file tree Collapse file tree 1 file changed +23
-8
lines changed Original file line number Diff line number Diff line change 11
11
### Basic usage
12
12
##### * Set-Cookie header*
13
13
14
- 1 . Instantiate a cookie setup using ` ResponseHeaders ` context and configure with array
15
- of directives/attributes (or builder methods) when their value needs to be specified
16
- (see [ ` directives() ` ] ( /src/Cookie/CookieSetup.php#L48 ) method):
14
+ 1 . Instantiate a cookie builder using ` ResponseHeaders ` context:
17
15
18
- $context = new ResponseHeaders();
19
- $cookieSetup = $context->directives([
16
+ $headers = new ResponseHeaders();
17
+ $cookieSetup = new CookieSetup($headers);
18
+
19
+ Alternatively, instantiating ` CookieSetup ` is possible with ` ResponseHeaders ` method:
20
+
21
+ $cookieSetup = $context->cookieSetup();
22
+
23
+ 2 . Configure cookie with array of its directives/attributes
24
+ (see [ ` CookieSetup::directives() ` ] ( /src/Cookie/CookieSetup.php#L48 ) method):
25
+
26
+ $cookieSetup->directives([
20
27
'Domain' => 'example.com',
21
28
'Path' => '/admin',
22
29
'Expires' => new DateTime(...),
26
33
'SameSite' => 'Strict'
27
34
]);
28
35
29
- Modifying setup object is possible with its mutator methods.
36
+ Modifying setup object is also possible with its builder methods:
37
+
38
+ $cookieSetup->domain('example.com')
39
+ ->path('/admin')
40
+ ->expires(new DateTime(...))
41
+ ->maxAge(1234)
42
+ ->secure()
43
+ ->httpOnly()
44
+ ->sameSite('Strict');
30
45
31
- 2 . Instantiate [ ` Cookie ` ] ( /src/Cookie.php ) type object with its name:
46
+ 3 . Instantiate [ ` Cookie ` ] ( /src/Cookie.php ) type object with its name:
32
47
33
48
$cookie = $cookieSetup->cookie('MyCookie');
34
49
35
- 3 . Send value:
50
+ 4 . Send value:
36
51
37
52
$cookie->send('value');
38
53
You can’t perform that action at this time.
0 commit comments