Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 3f2a770

Browse files
authored
updated the readme for the new classes (#2)
1 parent 7c89ca0 commit 3f2a770

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

README.md

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use Narrowspark\Http\Message\Util\InteractsWithAcceptLanguage;
3131
$request = new Request();
3232
$request = $request->withHeader('Accept-Language', 'zh, en-us; q=0.8, en; q=0.6');
3333

34-
return InteractsWithAcceptLanguage::getLanguages($request); // ['zh', 'en', 'en_US']
34+
return InteractsWithAcceptLanguage::getLanguages($request); // => ['zh', 'en', 'en_US']
3535

3636
```
3737

@@ -46,7 +46,7 @@ use Narrowspark\Http\Message\Util\InteractsWithAuthorization;
4646
$request = new Request();
4747
$request = $request->withHeader('Authorization', 'Basic QWxhZGRpbjpPcGVuU2VzYW1l');
4848

49-
return InteractsWithAuthorization::getAuthorization($request); // ['Basic', 'QWxhZGRpbjpPcGVuU2VzYW1l']
49+
return InteractsWithAuthorization::getAuthorization($request); // => ['Basic', 'QWxhZGRpbjpPcGVuU2VzYW1l']
5050

5151
```
5252

@@ -61,18 +61,58 @@ use Narrowspark\Http\Message\Util\InteractsWithContentTypes;
6161
$request = new Request();
6262
$request = $request->withHeader('Content-Type', 'application/json, */*');
6363

64-
return InteractsWithContentTypes::isJson($request); // true
64+
return InteractsWithContentTypes::isJson($request); // => true
6565

6666
$request = $request->withHeader('X-Pjax', 'true');
6767

68-
return InteractsWithContentTypes::isPjax($request); // true
68+
return InteractsWithContentTypes::isPjax($request); // => true
6969

7070
$request = $request->withHeader('X-Requested-With', 'XMLHttpRequest');
7171

72-
return InteractsWithContentTypes::isAjax($request); // true
72+
return InteractsWithContentTypes::isAjax($request); // => true
7373

7474
```
7575

76+
Here's an example using the HeaderUtils class:
77+
``` php
78+
<?php
79+
declare(strict_types=1);
80+
81+
use Narrowspark\Http\Message\Util\HeaderUtils;
82+
83+
return HeaderUtils::split("da, en-gb;q=0.8", ",;"); // => array(array('da'), array('en-gb', 'q=0.8'))
84+
85+
or
86+
87+
return HeaderUtils::combine(array(array("foo", "abc"), array("bar"))); // => array("foo" => "abc", "bar" => true)
88+
89+
or
90+
91+
return HeaderUtils::toString(array("foo" => "abc", "bar" => true, "baz" => "a b c"), ","); // => 'foo=abc, bar, baz="a b c"'
92+
93+
or
94+
95+
return HeaderUtils::quote('foo bar'); // => "foo bar"
96+
97+
or
98+
99+
return HeaderUtils::unquote('"foo bar"'); // => foo bar
100+
```
101+
102+
Here's an example using the InteractsWithDisposition class:
103+
``` php
104+
<?php
105+
declare(strict_types=1);
106+
107+
use Narrowspark\Http\Message\Util\InteractsWithDisposition;
108+
109+
$response = new Response();
110+
111+
$response = InteractsWithDisposition::makeDisposition($response, InteractsWithDisposition::DISPOSITION_ATTACHMENT, 'foo.html');
112+
113+
return $response->getHeaderLine('Content-Disposition'); // => attachment; filename=foo.html
114+
```
115+
76116
Testing
77117
------------
78118

0 commit comments

Comments
 (0)