Skip to content

Commit

Permalink
update something. readme
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Oct 20, 2017
1 parent c109108 commit af334b1
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 8 deletions.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,59 @@ git clone https://git.oschina.net/inhere/php-http.git // git@osc
git clone https://github.com/inhere/php-http.git // github
```

## usage

### basic

```php
use Inhere\Http\Request;
use Inhere\Http\Response;

$request = new Request($method, $uri);
$response = new Response($code);
... ...
```

### use factory

```php
use Inhere\Http\HttpFactory;

$request = HttpFactory::createRequest($method, $uri);
$request = HttpFactory::createRequestFromArray($_SERVER);

$response = HttpFactory::createResponse($code);

```

### Extended

```php
use Inhere\Http\Request;
use Inhere\Http\Extra\ExtendedRequestTrait;

class MyRequest extends Request {
use ExtendedRequestTrait;
}

//

$request = new MyRequest(...);

$age = $request->getInt('age');
$name = $request->getTrimmed('name');

```

```php
use Inhere\Http\Response;
use Inhere\Http\Extra\ExtendedResponseTrait;

class MyResponse extends Response {
use ExtendedResponseTrait;
}
```

## license

MIT
33 changes: 27 additions & 6 deletions src/Extra/Request.php → src/Extra/ExtendedRequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@
use Inhere\Library\Types;

/**
* Class Request
* trait ExtendedRequestTrait
*
* ```php
* use Inhere\Http\Request;
*
* class MyRequest extends Request {
* use ExtendedRequestTrait;
* }
* ```
*
* @package Inhere\Http\Extra
*
* @method string getRaw($name, $default = null) Get raw data
Expand All @@ -31,13 +40,23 @@
* @method string getUrl($name, $default = null) Get URL
*
* @property Uri $uri;
*
* // there methods at the class Request.
*
* @method string getHeaderLine(string $name)
* @method boolean isAjax()
* @method string getRequestTarget()
* @method array getUploadedFiles()
* @method array getQueryParams()
* @method array getParams()
* @method mixed getParam($key, $default = null)
*/
class Request extends \Inhere\Http\Request
trait ExtendedRequestTrait
{
/**
* return raw data
*/
const FILTER_RAW = 'raw';
private static $rawFilter = 'raw';

/**
* @var array
Expand All @@ -56,6 +75,8 @@ class Request extends \Inhere\Http\Request
'boolean' => 'bool',
// (string)$var
'string' => 'string',
// (array)$var
'array' => 'array',

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

/**
* @param $value
* @param $filter
* @param string|callable $filter
* @return mixed|null
*/
public function filtering($value, $filter = self::FILTER_RAW)
public function filtering($value, $filter = null)
{
if ($filter === self::FILTER_RAW) {
if (!$filter || $filter === self::$rawFilter) {
return $value;
}

Expand Down
13 changes: 11 additions & 2 deletions src/Extra/Response.php → src/Extra/ExtendedResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@
use Psr\Http\Message\UriInterface;

/**
* Class Response
* trait ExtendedResponseTrait
*
* ```php
* use Inhere\Http\Response;
*
* class MyResponse extends Response {
* use ExtendedResponseTrait;
* }
* ```
*
* @package Inhere\Http\Extra
*/
class Response extends \Inhere\Http\Response
trait ExtendedResponseTrait
{
/*******************************************************************************
* Response Helpers
Expand Down

0 comments on commit af334b1

Please sign in to comment.