Skip to content

Commit c28cc0a

Browse files
committed
Extended usage description of Set-Cookie header
1 parent 92a1736 commit c28cc0a

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

README.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@
1111
### Basic usage
1212
##### *Set-Cookie header*
1313

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:
1715

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([
2027
'Domain' => 'example.com',
2128
'Path' => '/admin',
2229
'Expires' => new DateTime(...),
@@ -26,13 +33,21 @@
2633
'SameSite' => 'Strict'
2734
]);
2835

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');
3045

31-
2. Instantiate [`Cookie`](/src/Cookie.php) type object with its name:
46+
3. Instantiate [`Cookie`](/src/Cookie.php) type object with its name:
3247

3348
$cookie = $cookieSetup->cookie('MyCookie');
3449

35-
3. Send value:
50+
4. Send value:
3651

3752
$cookie->send('value');
3853

0 commit comments

Comments
 (0)