Skip to content

Commit af334b1

Browse files
committed
update something. readme
1 parent c109108 commit af334b1

File tree

3 files changed

+91
-8
lines changed

3 files changed

+91
-8
lines changed

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,59 @@ git clone https://git.oschina.net/inhere/php-http.git // git@osc
2626
git clone https://github.com/inhere/php-http.git // github
2727
```
2828

29+
## usage
30+
31+
### basic
32+
33+
```php
34+
use Inhere\Http\Request;
35+
use Inhere\Http\Response;
36+
37+
$request = new Request($method, $uri);
38+
$response = new Response($code);
39+
... ...
40+
```
41+
42+
### use factory
43+
44+
```php
45+
use Inhere\Http\HttpFactory;
46+
47+
$request = HttpFactory::createRequest($method, $uri);
48+
$request = HttpFactory::createRequestFromArray($_SERVER);
49+
50+
$response = HttpFactory::createResponse($code);
51+
52+
```
53+
54+
### Extended
55+
56+
```php
57+
use Inhere\Http\Request;
58+
use Inhere\Http\Extra\ExtendedRequestTrait;
59+
60+
class MyRequest extends Request {
61+
use ExtendedRequestTrait;
62+
}
63+
64+
//
65+
66+
$request = new MyRequest(...);
67+
68+
$age = $request->getInt('age');
69+
$name = $request->getTrimmed('name');
70+
71+
```
72+
73+
```php
74+
use Inhere\Http\Response;
75+
use Inhere\Http\Extra\ExtendedResponseTrait;
76+
77+
class MyResponse extends Response {
78+
use ExtendedResponseTrait;
79+
}
80+
```
81+
2982
## license
3083

3184
MIT
Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@
1515
use Inhere\Library\Types;
1616

1717
/**
18-
* Class Request
18+
* trait ExtendedRequestTrait
19+
*
20+
* ```php
21+
* use Inhere\Http\Request;
22+
*
23+
* class MyRequest extends Request {
24+
* use ExtendedRequestTrait;
25+
* }
26+
* ```
27+
*
1928
* @package Inhere\Http\Extra
2029
*
2130
* @method string getRaw($name, $default = null) Get raw data
@@ -31,13 +40,23 @@
3140
* @method string getUrl($name, $default = null) Get URL
3241
*
3342
* @property Uri $uri;
43+
*
44+
* // there methods at the class Request.
45+
*
46+
* @method string getHeaderLine(string $name)
47+
* @method boolean isAjax()
48+
* @method string getRequestTarget()
49+
* @method array getUploadedFiles()
50+
* @method array getQueryParams()
51+
* @method array getParams()
52+
* @method mixed getParam($key, $default = null)
3453
*/
35-
class Request extends \Inhere\Http\Request
54+
trait ExtendedRequestTrait
3655
{
3756
/**
3857
* return raw data
3958
*/
40-
const FILTER_RAW = 'raw';
59+
private static $rawFilter = 'raw';
4160

4261
/**
4362
* @var array
@@ -56,6 +75,8 @@ class Request extends \Inhere\Http\Request
5675
'boolean' => 'bool',
5776
// (string)$var
5877
'string' => 'string',
78+
// (array)$var
79+
'array' => 'array',
5980

6081
// trim($var)
6182
'trimmed' => [FilterList::class, 'trim'],
@@ -200,12 +221,12 @@ public function __call($name, array $arguments)
200221

201222
/**
202223
* @param $value
203-
* @param $filter
224+
* @param string|callable $filter
204225
* @return mixed|null
205226
*/
206-
public function filtering($value, $filter = self::FILTER_RAW)
227+
public function filtering($value, $filter = null)
207228
{
208-
if ($filter === self::FILTER_RAW) {
229+
if (!$filter || $filter === self::$rawFilter) {
209230
return $value;
210231
}
211232

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@
1212
use Psr\Http\Message\UriInterface;
1313

1414
/**
15-
* Class Response
15+
* trait ExtendedResponseTrait
16+
*
17+
* ```php
18+
* use Inhere\Http\Response;
19+
*
20+
* class MyResponse extends Response {
21+
* use ExtendedResponseTrait;
22+
* }
23+
* ```
24+
*
1625
* @package Inhere\Http\Extra
1726
*/
18-
class Response extends \Inhere\Http\Response
27+
trait ExtendedResponseTrait
1928
{
2029
/*******************************************************************************
2130
* Response Helpers

0 commit comments

Comments
 (0)