From 2322e2279a7a4f18c6a51c3dbc49e38b3988335c Mon Sep 17 00:00:00 2001 From: l0gicgate Date: Tue, 30 Oct 2018 14:51:13 -0600 Subject: [PATCH 1/8] add detailed README with all of the decorated object methods --- README.md | 240 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 234 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0ab7dcd..f00eb78 100644 --- a/README.md +++ b/README.md @@ -13,24 +13,251 @@ It's recommended that you use [Composer](https://getcomposer.org/) to install this library. ```bash -$ composer require slim/http "^0.1" +$ composer require slim/http "^0.5" ``` This will install the `slim/http` component and all required dependencies. PHP 7.1, or newer, is required. +## Tests + +To execute the test suite, you'll need to install all development dependencies + +```bash +$ composer install +$ composer test +``` + ## Usage -Coming soon. +The Decoration Repo Provides 3 Factories which instantiate the Decorators. They respectively return PSR-7 Compatible Interfaces +- DecoratedResponseFactory +- DecoratedServerRequestFactory +- DecoratedUriFactory -## Tests +## Example For Instantiating a Decorated Nyholm/Psr7 Response +```php +createResponse(200, 'OK'); +$response = $response->withJson(['data' => [1, 2, 3]]); + +``` + +## Example For Instantiating a Decorated Zend Diactoros Response +```php +createResponse(200, 'OK'); +$response = $response->withJson(['data' => [1, 2, 3]]); -```bash -$ phpunit ``` +## Decoratored Response Object Methods +The decorated `ResponseInterface` provides the following additional methods: + + +#### `ResponseDecorator::withJson($data, $status, $options, $depth)` #### +| Parameter | Type | Description | +|-----------|----------|-------------------------| +| **$data** | `mixed` | The data to encode | +| **$status** | `int|null` | The HTTP Status Code | +| **$depth** | `int` | JSON encoding max depth | + +#### `ResponseDecorator::withRedirect($url, $status)` #### +| Parameter | Type | Description | +|-----------|----------|-------------------------| +| **$url** | `string` | The redirect destination url | +| **$status** | `int|null` | The HTTP Status Code | + +#### `ResponseDecorator::write($data)` #### +| Parameter | Type | Description | +|-----------|----------|-------------------------| +| **$url** | `string` | The data to write to the `Response` body | + +#### `ResponseDecorator::isClientError()` #### +Assert the current `Response` status code is between **400** and **500** + +#### `ResponseDecorator::isEmpty()` #### +Assert the current `Response` status code is **204, 205** or **304** + +#### `ResponseDecorator::isForbidden()` #### +Assert the current `Response` status code is **403** + +#### `ResponseDecorator::isInformational()` #### +Assert the current `Response` status code is between **100** and **200** + +#### `ResponseDecorator::isOk()` #### +Assert the current `Response` status code is **200** + +#### `ResponseDecorator::isNotFound()` #### +Assert the current `Response` status code is **404** + +#### `ResponseDecorator::isRedirection()` #### +Assert the current `Response` status code is between **300** and **400** + +#### `ResponseDecorator::isServerError()` #### +Assert the current `Response` status code is between **500** and **600** + +#### `ResponseDecorator::isSuccessful()` #### +Assert the current `Response` status code is between **200** and **300** + +#### `ResponseDecorator::__toString()` #### +Will return a string formatted representation of the Response +``` +HTTP/1.1 200 OK +Content-Type: application/json;charset=utf-8 + +{"Hello": "World"} +``` + +## Decoratored ServerRequest Object Methods +The decorated `ServerRequestInterface` provides the following additional methods: + + +#### `ServerRequestDecorator::withAttributes($attributes)` #### +| Parameter | Type | Description | +|-----------|----------|-------------------------| +| **$attributes** | `array` | Attributes to be appended to the request | + +#### `ServerRequestDecorator::getContentCharset()` #### +Returns the detected charset from the `Content-Type` header.Returns `null` if no value is present. + +#### `ServerRequestDecorator::getContentType()` #### +Returns the value from the `Content-Type` header. Returns `null` if no value is present. + +#### `ServerRequestDecorator::getContentLength()` #### +Returns the value from the `Content-Length` header. Returns `null` if no value is present. + +#### `ServerRequestDecorator::getCookieParam($key, $default)` #### +| Parameter | Type | Description | +|-----------|----------|-------------------------| +| **$key** | `string` | The attribute name | +| **$default** | `mixed|null` | Default value to return if the attribute does not exist | + +#### `ServerRequestDecorator::getMediaType()` #### +Returns the first detected value from the `Content-Type` header. Returns `null` if no value is present. + +#### `ServerRequestDecorator::getMediaTypeParams()` #### +Returns an array of detected values from the `Content-Type` header. Returns an empty array if no values are present. + +#### `ServerRequestDecorator::getParam($key, $default)` #### +Returns the value from key in `$_POST` or `$_GET` + +| Parameter | Type | Description | +|-----------|----------|-------------------------| +| **$key** | `string` | The attribute name | +| **$default** | `mixed|null` | Default value to return if the attribute does not exist | + +#### `ServerRequestDecorator::getParams()` #### +Returns a merged associative array of the `$_POST` and `$_GET` parameters. + +#### `ServerRequestDecorator::getParsedBody()` #### +Returns the parsed body from the underlying `ServerRequest` if it already has been parsed by the underlying PSR-7 implementation. If the underlying `ServerRequest` parsed body is empty, our decorator attempts to detect the content type and parse the body using one of the registered media type parsers. + +The default media type parsers support: +- JSON +- XML + +You can register your own media type parser using the `ServerRequestDecorator::registerMediaTypeParser()` method. + + +#### `ServerRequestDecorator::getParsedBodyParam($key, $default)` #### +Returns the value from key in the parsed `ServerRequest` body + +| Parameter | Type | Description | +|-----------|----------|-------------------------| +| **$key** | `string` | The attribute name | +| **$default** | `mixed|null` | Default value to return if the attribute does not exist | + +#### `ServerRequestDecorator::getQueryParam($key, $default)` #### +Returns the value from key in the parsed `ServerRequest` query string + +| Parameter | Type | Description | +|-----------|----------|-------------------------| +| **$key** | `string` | The attribute name | +| **$default** | `mixed|null` | Default value to return if the attribute does not exist | + +#### `ServerRequestDecorator::getServerParam($key, $default)` #### +Returns the value from key in parsed server parameters from the underlying `ServerRequest` object + +| Parameter | Type | Description | +|-----------|----------|-------------------------| +| **$key** | `string` | The attribute name | +| **$default** | `mixed|null` | Default value to return if the attribute does not exist | + +#### `ServerRequestDecorator::registerMediaTypeParser($key, $default)` #### +Returns the value from key in parsed server parameters from the underlying `ServerRequest` object + +| Parameter | Type | Description | +|-----------|----------|-------------------------| +| **$mediaType** | `string` | A HTTP media type (excluding content-type params) | +| **$callable** | `callable` | A callable that returns parsed contents for media type | + +#### `ServerRequestDecorator::isDelete()` #### +Asserts that the request method is `DELETE` + +#### `ServerRequestDecorator::isGet()` #### +Asserts that the request method is `GET` + +#### `ServerRequestDecorator::isHead()` #### +Asserts that the request method is `HEAD` + +#### `ServerRequestDecorator::isMethod($method)` #### +| Parameter | Type | Description | +|-----------|----------|-------------------------| +| **$method** | `string` | The method name | + +#### `ServerRequestDecorator::isOptions()` #### +Asserts that the request method is `OPTIONS` + +#### `ServerRequestDecorator::isPatch()` #### +Asserts that the request method is `PATCH` + +#### `ServerRequestDecorator::isPost()` #### +Asserts that the request method is `POST` + +#### `ServerRequestDecorator::isPut()` #### +Asserts that the request method is `PUT` + +#### `ServerRequestDecorator::isXhr()` #### +Asserts that the header `X-Requested-With` is `XMLHttpRequest` + ## Contributing Please see [CONTRIBUTING](CONTRIBUTING.md) for details. @@ -45,6 +272,7 @@ instead of using the issue tracker. - [Josh Lockhart](https://github.com/codeguy) - [Andrew Smith](https://github.com/silentworks) - [Rob Allen](https://github.com/akrabat) +- [Pierre Bérubé](https://github.com/l0gicgate) - [All Contributors](../../contributors) ## License From 55264031ed69d1e11ca2efa97c3dafe0669f91a1 Mon Sep 17 00:00:00 2001 From: l0gicgate Date: Tue, 30 Oct 2018 14:53:45 -0600 Subject: [PATCH 2/8] add UriDecorator methods --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f00eb78..84aeb96 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,9 @@ $ composer test ## Usage The Decoration Repo Provides 3 Factories which instantiate the Decorators. They respectively return PSR-7 Compatible Interfaces -- DecoratedResponseFactory -- DecoratedServerRequestFactory -- DecoratedUriFactory +- `DecoratedResponseFactory` +- `DecoratedServerRequestFactory` +- `DecoratedUriFactory` ## Example For Instantiating a Decorated Nyholm/Psr7 Response ```php @@ -258,6 +258,13 @@ Asserts that the request method is `PUT` #### `ServerRequestDecorator::isXhr()` #### Asserts that the header `X-Requested-With` is `XMLHttpRequest` +## Decoratored Uri Object Methods +The decorated `UriInterface` provides the following additional methods: + +#### `UriDecorator::getBaseUrl()` #### +Returns the fully qualified base URL + + ## Contributing Please see [CONTRIBUTING](CONTRIBUTING.md) for details. From bb25eb82434d8a98361ca16bdfb55acec7b9e1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20B=C3=A9rub=C3=A9?= Date: Tue, 30 Oct 2018 20:04:06 -0600 Subject: [PATCH 3/8] fix markdown errors --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 84aeb96..1229e14 100644 --- a/README.md +++ b/README.md @@ -96,14 +96,14 @@ The decorated `ResponseInterface` provides the following additional methods: | Parameter | Type | Description | |-----------|----------|-------------------------| | **$data** | `mixed` | The data to encode | -| **$status** | `int|null` | The HTTP Status Code | +| **$status** | `int` | The HTTP Status Code | | **$depth** | `int` | JSON encoding max depth | #### `ResponseDecorator::withRedirect($url, $status)` #### | Parameter | Type | Description | |-----------|----------|-------------------------| | **$url** | `string` | The redirect destination url | -| **$status** | `int|null` | The HTTP Status Code | +| **$status** | `int` | The HTTP Status Code | #### `ResponseDecorator::write($data)` #### | Parameter | Type | Description | @@ -168,7 +168,7 @@ Returns the value from the `Content-Length` header. Returns `null` if no value i | Parameter | Type | Description | |-----------|----------|-------------------------| | **$key** | `string` | The attribute name | -| **$default** | `mixed|null` | Default value to return if the attribute does not exist | +| **$default** | `mixed` | Default value to return if the attribute does not exist | #### `ServerRequestDecorator::getMediaType()` #### Returns the first detected value from the `Content-Type` header. Returns `null` if no value is present. @@ -182,7 +182,7 @@ Returns the value from key in `$_POST` or `$_GET` | Parameter | Type | Description | |-----------|----------|-------------------------| | **$key** | `string` | The attribute name | -| **$default** | `mixed|null` | Default value to return if the attribute does not exist | +| **$default** | `mixed` | Default value to return if the attribute does not exist | #### `ServerRequestDecorator::getParams()` #### Returns a merged associative array of the `$_POST` and `$_GET` parameters. @@ -203,7 +203,7 @@ Returns the value from key in the parsed `ServerRequest` body | Parameter | Type | Description | |-----------|----------|-------------------------| | **$key** | `string` | The attribute name | -| **$default** | `mixed|null` | Default value to return if the attribute does not exist | +| **$default** | `mixed` | Default value to return if the attribute does not exist | #### `ServerRequestDecorator::getQueryParam($key, $default)` #### Returns the value from key in the parsed `ServerRequest` query string @@ -211,7 +211,7 @@ Returns the value from key in the parsed `ServerRequest` query string | Parameter | Type | Description | |-----------|----------|-------------------------| | **$key** | `string` | The attribute name | -| **$default** | `mixed|null` | Default value to return if the attribute does not exist | +| **$default** | `mixed` | Default value to return if the attribute does not exist | #### `ServerRequestDecorator::getServerParam($key, $default)` #### Returns the value from key in parsed server parameters from the underlying `ServerRequest` object @@ -219,7 +219,7 @@ Returns the value from key in parsed server parameters from the underlying `Serv | Parameter | Type | Description | |-----------|----------|-------------------------| | **$key** | `string` | The attribute name | -| **$default** | `mixed|null` | Default value to return if the attribute does not exist | +| **$default** | `mixed` | Default value to return if the attribute does not exist | #### `ServerRequestDecorator::registerMediaTypeParser($key, $default)` #### Returns the value from key in parsed server parameters from the underlying `ServerRequest` object From e9e2f4510fbd969d30421334dceb1caad694547b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20B=C3=A9rub=C3=A9?= Date: Tue, 30 Oct 2018 20:16:08 -0600 Subject: [PATCH 4/8] fix markdown errors and white spacing --- README.md | 62 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 1229e14..d69435c 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ $ composer require slim/http "^0.5" This will install the `slim/http` component and all required dependencies. PHP 7.1, or newer, is required. - +

## Tests To execute the test suite, you'll need to install all development dependencies @@ -27,8 +27,9 @@ To execute the test suite, you'll need to install all development dependencies $ composer install $ composer test ``` +
-## Usage +## Usage The Decoration Repo Provides 3 Factories which instantiate the Decorators. They respectively return PSR-7 Compatible Interfaces - `DecoratedResponseFactory` @@ -60,6 +61,7 @@ $response = $decoratedResponseFactory->createResponse(200, 'OK'); $response = $response->withJson(['data' => [1, 2, 3]]); ``` +
## Example For Instantiating a Decorated Zend Diactoros Response ```php @@ -87,28 +89,28 @@ $response = $decoratedResponseFactory->createResponse(200, 'OK'); $response = $response->withJson(['data' => [1, 2, 3]]); ``` +
## Decoratored Response Object Methods The decorated `ResponseInterface` provides the following additional methods: - #### `ResponseDecorator::withJson($data, $status, $options, $depth)` #### -| Parameter | Type | Description | -|-----------|----------|-------------------------| -| **$data** | `mixed` | The data to encode | -| **$status** | `int` | The HTTP Status Code | -| **$depth** | `int` | JSON encoding max depth | +| Parameter | Type | Description | +|-------------|---------|-------------------------| +| **$data** | `mixed` | The data to encode | +| **$status** | `int` | The HTTP Status Code | +| **$depth** | `int` | JSON encoding max depth | #### `ResponseDecorator::withRedirect($url, $status)` #### -| Parameter | Type | Description | -|-----------|----------|-------------------------| -| **$url** | `string` | The redirect destination url | -| **$status** | `int` | The HTTP Status Code | +| Parameter | Type | Description | +|-------------|----------|------------------------------| +| **$url** | `string` | The redirect destination url | +| **$status** | `int` | The HTTP Status Code | #### `ResponseDecorator::write($data)` #### -| Parameter | Type | Description | -|-----------|----------|-------------------------| -| **$url** | `string` | The data to write to the `Response` body | +| Parameter | Type | Description | +|-----------|----------|------------------------------------------| +| **$url** | `string` | The data to write to the `Response` body | #### `ResponseDecorator::isClientError()` #### Assert the current `Response` status code is between **400** and **500** @@ -145,18 +147,18 @@ Content-Type: application/json;charset=utf-8 {"Hello": "World"} ``` +
## Decoratored ServerRequest Object Methods The decorated `ServerRequestInterface` provides the following additional methods: - #### `ServerRequestDecorator::withAttributes($attributes)` #### -| Parameter | Type | Description | -|-----------|----------|-------------------------| -| **$attributes** | `array` | Attributes to be appended to the request | +| Parameter | Type | Description | +|-----------------|-----------|------------------------------------------| +| **$attributes** | `array` | Attributes to be appended to the request | #### `ServerRequestDecorator::getContentCharset()` #### -Returns the detected charset from the `Content-Type` header.Returns `null` if no value is present. +Returns the detected charset from the `Content-Type` header. Returns `null` if no value is present. #### `ServerRequestDecorator::getContentType()` #### Returns the value from the `Content-Type` header. Returns `null` if no value is present. @@ -257,32 +259,32 @@ Asserts that the request method is `PUT` #### `ServerRequestDecorator::isXhr()` #### Asserts that the header `X-Requested-With` is `XMLHttpRequest` - +
+
## Decoratored Uri Object Methods The decorated `UriInterface` provides the following additional methods: #### `UriDecorator::getBaseUrl()` #### Returns the fully qualified base URL - - +
+
## Contributing - Please see [CONTRIBUTING](CONTRIBUTING.md) for details. - +
+
## Security - If you discover security related issues, please email security@slimframework.com instead of using the issue tracker. - +
+
## Credits - - [Josh Lockhart](https://github.com/codeguy) - [Andrew Smith](https://github.com/silentworks) - [Rob Allen](https://github.com/akrabat) - [Pierre Bérubé](https://github.com/l0gicgate) - [All Contributors](../../contributors) - +
+
## License - This component is licensed under the MIT license. See [License File](LICENSE.md) for more information. From 7a078cd5a404e76be3776f7be445beff382d38a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20B=C3=A9rub=C3=A9?= Date: Tue, 30 Oct 2018 21:24:40 -0600 Subject: [PATCH 5/8] fix punctuation, verbage and method ordering --- README.md | 119 +++++++++++++++++++++++++++--------------------------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index d69435c..e31c0b5 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,10 @@ PHP 7.1, or newer, is required.

## Tests -To execute the test suite, you'll need to install all development dependencies +To execute the test suite, you'll need to install all development dependencies. ```bash +$ git clone https://github.com/slimphp/Slim-Http $ composer install $ composer test ``` @@ -31,7 +32,7 @@ $ composer test ## Usage -The Decoration Repo Provides 3 Factories which instantiate the Decorators. They respectively return PSR-7 Compatible Interfaces +The Decoration Repo Provides 3 Factories which instantiate the Decorators. They respectively return PSR-7 Compatible Interfaces. - `DecoratedResponseFactory` - `DecoratedServerRequestFactory` - `DecoratedUriFactory` @@ -113,34 +114,34 @@ The decorated `ResponseInterface` provides the following additional methods: | **$url** | `string` | The data to write to the `Response` body | #### `ResponseDecorator::isClientError()` #### -Assert the current `Response` status code is between **400** and **500** +Assert the underlying response's status code is between **400** and **500**. #### `ResponseDecorator::isEmpty()` #### -Assert the current `Response` status code is **204, 205** or **304** +Assert the underlying response's status code is **204, 205** or **304**. #### `ResponseDecorator::isForbidden()` #### -Assert the current `Response` status code is **403** +Assert the underlying response's status code is **403**. #### `ResponseDecorator::isInformational()` #### -Assert the current `Response` status code is between **100** and **200** +Assert the underlying response's status code is between **100** and **200**. #### `ResponseDecorator::isOk()` #### -Assert the current `Response` status code is **200** +Assert the underlying response's status code is **200**. #### `ResponseDecorator::isNotFound()` #### -Assert the current `Response` status code is **404** +Assert the underlying response's status code is **404**. #### `ResponseDecorator::isRedirection()` #### -Assert the current `Response` status code is between **300** and **400** +Assert the underlying response's status code is between **300** and **400**. #### `ResponseDecorator::isServerError()` #### -Assert the current `Response` status code is between **500** and **600** +Assert the underlying response's status code is between **500** and **600**. #### `ResponseDecorator::isSuccessful()` #### -Assert the current `Response` status code is between **200** and **300** +Assert the underlying response's status code is between **200** and **300**. #### `ResponseDecorator::__toString()` #### -Will return a string formatted representation of the Response +Will return a string formatted representation of the underlying response object. ``` HTTP/1.1 200 OK Content-Type: application/json;charset=utf-8 @@ -158,39 +159,39 @@ The decorated `ServerRequestInterface` provides the following additional methods | **$attributes** | `array` | Attributes to be appended to the request | #### `ServerRequestDecorator::getContentCharset()` #### -Returns the detected charset from the `Content-Type` header. Returns `null` if no value is present. +Returns the detected charset from the `Content-Type` header of the underlying server request object. Returns `null` if no value is present. #### `ServerRequestDecorator::getContentType()` #### -Returns the value from the `Content-Type` header. Returns `null` if no value is present. +Returns the value from the `Content-Type` header of the underlying server request object. Returns `null` if no value is present. #### `ServerRequestDecorator::getContentLength()` #### -Returns the value from the `Content-Length` header. Returns `null` if no value is present. +Returns the value from the `Content-Length` header of the underlying server request object. Returns `null` if no value is present. #### `ServerRequestDecorator::getCookieParam($key, $default)` #### -| Parameter | Type | Description | -|-----------|----------|-------------------------| -| **$key** | `string` | The attribute name | -| **$default** | `mixed` | Default value to return if the attribute does not exist | +| Parameter | Type | Description | +|---------------|----------|--------------------------------------------------------| +| **$key** | `string` | The attribute name | +| **$default** | `mixed` | Default value to return if the attribute does not exist | #### `ServerRequestDecorator::getMediaType()` #### -Returns the first detected value from the `Content-Type` header. Returns `null` if no value is present. +Returns the first detected value from the `Content-Type` header of the underlying server request object. Returns `null` if no value is present. #### `ServerRequestDecorator::getMediaTypeParams()` #### -Returns an array of detected values from the `Content-Type` header. Returns an empty array if no values are present. +Returns an array of detected values from the `Content-Type` header of the underlying server request object. Returns an empty array if no values are present. #### `ServerRequestDecorator::getParam($key, $default)` #### Returns the value from key in `$_POST` or `$_GET` -| Parameter | Type | Description | -|-----------|----------|-------------------------| -| **$key** | `string` | The attribute name | -| **$default** | `mixed` | Default value to return if the attribute does not exist | +| Parameter | Type | Description | +|--------------|----------|---------------------------------------------------------| +| **$key** | `string` | The attribute name | +| **$default** | `mixed` | Default value to return if the attribute does not exist | #### `ServerRequestDecorator::getParams()` #### Returns a merged associative array of the `$_POST` and `$_GET` parameters. #### `ServerRequestDecorator::getParsedBody()` #### -Returns the parsed body from the underlying `ServerRequest` if it already has been parsed by the underlying PSR-7 implementation. If the underlying `ServerRequest` parsed body is empty, our decorator attempts to detect the content type and parse the body using one of the registered media type parsers. +Returns the parsed body from the underlying server request object if it already has been parsed by the underlying PSR-7 implementation. If the parsed body is empty, our decorator attempts to detect the content type and parse the body using one of the registered media type parsers. The default media type parsers support: - JSON @@ -200,72 +201,72 @@ You can register your own media type parser using the `ServerRequestDecorator::r #### `ServerRequestDecorator::getParsedBodyParam($key, $default)` #### -Returns the value from key in the parsed `ServerRequest` body +Returns the value from key in the parsed body of the underlying server request object. -| Parameter | Type | Description | -|-----------|----------|-------------------------| -| **$key** | `string` | The attribute name | -| **$default** | `mixed` | Default value to return if the attribute does not exist | +| Parameter | Type | Description | +|--------------|----------|---------------------------------------------------------| +| **$key** | `string` | The attribute name | +| **$default** | `mixed` | Default value to return if the attribute does not exist | #### `ServerRequestDecorator::getQueryParam($key, $default)` #### Returns the value from key in the parsed `ServerRequest` query string -| Parameter | Type | Description | -|-----------|----------|-------------------------| -| **$key** | `string` | The attribute name | -| **$default** | `mixed` | Default value to return if the attribute does not exist | +| Parameter | Type | Description | +|---------------|----------|---------------------------------------------------------| +| **$key** | `string` | The attribute name | +| **$default** | `mixed` | Default value to return if the attribute does not exist | #### `ServerRequestDecorator::getServerParam($key, $default)` #### -Returns the value from key in parsed server parameters from the underlying `ServerRequest` object +Returns the value from key in parsed server parameters from the underlying underlying server request object. -| Parameter | Type | Description | -|-----------|----------|-------------------------| -| **$key** | `string` | The attribute name | -| **$default** | `mixed` | Default value to return if the attribute does not exist | +| Parameter | Type | Description | +|--------------|----------|----------------------------------------------------------| +| **$key** | `string` | The attribute name | +| **$default** | `mixed` | Default value to return if the attribute does not exist | #### `ServerRequestDecorator::registerMediaTypeParser($key, $default)` #### -Returns the value from key in parsed server parameters from the underlying `ServerRequest` object +Returns the value from key in parsed server parameters from the underlying server request object. -| Parameter | Type | Description | -|-----------|----------|-------------------------| -| **$mediaType** | `string` | A HTTP media type (excluding content-type params) | -| **$callable** | `callable` | A callable that returns parsed contents for media type | +| Parameter | Type | Description | +|----------------|------------|--------------------------------------------------------| +| **$mediaType** | `string` | A HTTP media type (excluding content-type params) | +| **$callable** | `callable` | A callable that returns parsed contents for media type | + +#### `ServerRequestDecorator::isMethod($method)` #### +| Parameter | Type | Description | +|-------------|----------|-----------------| +| **$method** | `string` | The method name | #### `ServerRequestDecorator::isDelete()` #### -Asserts that the request method is `DELETE` +Asserts that the underlying server request's method is `DELETE` #### `ServerRequestDecorator::isGet()` #### -Asserts that the request method is `GET` +Asserts that the underlying server request's method is `GET` #### `ServerRequestDecorator::isHead()` #### -Asserts that the request method is `HEAD` - -#### `ServerRequestDecorator::isMethod($method)` #### -| Parameter | Type | Description | -|-----------|----------|-------------------------| -| **$method** | `string` | The method name | +Asserts that the underlying server request's method is `HEAD` #### `ServerRequestDecorator::isOptions()` #### -Asserts that the request method is `OPTIONS` +Asserts that the underlying server request's method is `OPTIONS` #### `ServerRequestDecorator::isPatch()` #### -Asserts that the request method is `PATCH` +Asserts that the underlying server request's method is `PATCH` #### `ServerRequestDecorator::isPost()` #### -Asserts that the request method is `POST` +Asserts that the underlying server request's method is `POST` #### `ServerRequestDecorator::isPut()` #### -Asserts that the request method is `PUT` +Asserts that the underlying server request's method is `PUT` #### `ServerRequestDecorator::isXhr()` #### -Asserts that the header `X-Requested-With` is `XMLHttpRequest` +Asserts that the header `X-Requested-With` from the underlying server request is `XMLHttpRequest`

## Decoratored Uri Object Methods The decorated `UriInterface` provides the following additional methods: #### `UriDecorator::getBaseUrl()` #### -Returns the fully qualified base URL +Returns the fully qualified base URL of the underlying uri object.

## Contributing From 367404829a242eeda01f5458bb117ce571396eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20B=C3=A9rub=C3=A9?= Date: Thu, 1 Nov 2018 01:55:08 -0600 Subject: [PATCH 6/8] fix namespaces in examples --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e31c0b5..1892063 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ The Decoration Repo Provides 3 Factories which instantiate the Decorators. They createResponse(200, 'OK'); @@ -70,7 +70,7 @@ $response = $response->withJson(['data' => [1, 2, 3]]); use Zend\Diactoros\ResponseFactory; use Zend\Diactoros\StreamFactory; -use SlimPsr7Decorators\Factory\DecoratedResponseFactory; +use Slim\Http\Decorators\Factory\DecoratedResponseFactory; $responseFactory = new ResponseFactory(); $streamFactory = new StreamFactory(); @@ -83,7 +83,7 @@ $streamFactory = new StreamFactory(); $decoratedResponseFactory = new DecoratedResponseFactory($responseFactory, $streamFactory); /** - * @var \SlimPsr7Decorators\Decorators\DecoratedResponse $response + * @var \Slim\Http\Decorators\DecoratedResponse $response * The returned variable is a DecoratedResponse which has methods like withJson() */ $response = $decoratedResponseFactory->createResponse(200, 'OK'); From a5bf1f71ecfe28fb364a06c6385db72f237cf8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20B=C3=A9rub=C3=A9?= Date: Thu, 1 Nov 2018 01:56:53 -0600 Subject: [PATCH 7/8] fix namespaces in examples --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1892063..b6828a7 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ The Decoration Repo Provides 3 Factories which instantiate the Decorators. They createResponse(200, 'OK'); $response = $response->withJson(['data' => [1, 2, 3]]); @@ -70,7 +70,7 @@ $response = $response->withJson(['data' => [1, 2, 3]]); use Zend\Diactoros\ResponseFactory; use Zend\Diactoros\StreamFactory; -use Slim\Http\Decorators\Factory\DecoratedResponseFactory; +use Slim\Http\Factory\DecoratedResponseFactory; $responseFactory = new ResponseFactory(); $streamFactory = new StreamFactory(); @@ -83,8 +83,8 @@ $streamFactory = new StreamFactory(); $decoratedResponseFactory = new DecoratedResponseFactory($responseFactory, $streamFactory); /** - * @var \Slim\Http\Decorators\DecoratedResponse $response - * The returned variable is a DecoratedResponse which has methods like withJson() + * @var \Slim\Http\Decorators\ResponseDecorator $response + * The returned variable is a ResponseDecorator which has methods like withJson() */ $response = $decoratedResponseFactory->createResponse(200, 'OK'); $response = $response->withJson(['data' => [1, 2, 3]]); From 0e52691c7b9ec23c78db3b44814f134e959c0900 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Thu, 1 Nov 2018 13:05:53 +0000 Subject: [PATCH 8/8] Remove
and fix License link --- README.md | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index b6828a7..41c431b 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ $ composer require slim/http "^0.5" This will install the `slim/http` component and all required dependencies. PHP 7.1, or newer, is required. -

+ ## Tests To execute the test suite, you'll need to install all development dependencies. @@ -28,7 +28,7 @@ $ git clone https://github.com/slimphp/Slim-Http $ composer install $ composer test ``` -
+ ## Usage @@ -37,7 +37,7 @@ The Decoration Repo Provides 3 Factories which instantiate the Decorators. They - `DecoratedServerRequestFactory` - `DecoratedUriFactory` -## Example For Instantiating a Decorated Nyholm/Psr7 Response +## Example for Instantiating a Decorated Nyholm/Psr7 Response ```php createResponse(200, 'OK'); $response = $response->withJson(['data' => [1, 2, 3]]); ``` -
-## Example For Instantiating a Decorated Zend Diactoros Response + +## Example for Instantiating a Decorated Zend Diactoros Response ```php createResponse(200, 'OK'); $response = $response->withJson(['data' => [1, 2, 3]]); ``` -
+ ## Decoratored Response Object Methods The decorated `ResponseInterface` provides the following additional methods: @@ -148,7 +148,7 @@ Content-Type: application/json;charset=utf-8 {"Hello": "World"} ``` -
+ ## Decoratored ServerRequest Object Methods The decorated `ServerRequestInterface` provides the following additional methods: @@ -260,32 +260,28 @@ Asserts that the underlying server request's method is `PUT` #### `ServerRequestDecorator::isXhr()` #### Asserts that the header `X-Requested-With` from the underlying server request is `XMLHttpRequest` -
-
-## Decoratored Uri Object Methods + +## Decorated Uri Object Methods The decorated `UriInterface` provides the following additional methods: #### `UriDecorator::getBaseUrl()` #### Returns the fully qualified base URL of the underlying uri object. -
-
+ ## Contributing Please see [CONTRIBUTING](CONTRIBUTING.md) for details. -
-
+ ## Security If you discover security related issues, please email security@slimframework.com instead of using the issue tracker. -
-
+ ## Credits - [Josh Lockhart](https://github.com/codeguy) - [Andrew Smith](https://github.com/silentworks) - [Rob Allen](https://github.com/akrabat) - [Pierre Bérubé](https://github.com/l0gicgate) - [All Contributors](../../contributors) -
-
+ ## License -This component is licensed under the MIT license. See [License File](LICENSE.md) + +This component is licensed under the MIT license. See [License File](LICENSE) for more information.