Skip to content

Commit

Permalink
Refactored Response and added Status
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Feb 2, 2015
1 parent dfc609e commit eb52ded
Show file tree
Hide file tree
Showing 11 changed files with 571 additions and 337 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ php:

before_script:
- travis_retry composer self-update
- travis_retry composer --prefer-source install
- composer require satooshi/php-coveralls
- travis_retry composer install --prefer-source
- composer require satooshi/php-coveralls --prefer-source

script:
- mkdir -p build/logs
Expand Down
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ $file->to_array();

## Response

The response to a request is represented by a [Response](http://icanboogie.org/docs/class-ICanBoogie.HTTP.Response.html) instance.
The response to a request is represented by a [Response][] instance.

```php
<?php
Expand All @@ -264,11 +264,28 @@ $response();



### Redirect response

A redirect response can be easily created using a [RedirectResponse][] instance.

```php
<?php

use ICanBoogie\HTTP\RedirectResponse;

$response = new RedirectResponse('/to/redirect/location');
$response->status->code; // 302
$response->status->is_redirect; // true
```





## Headers

HTTP headers are represented by a [Headers](http://icanboogie.org/docs/class-ICanBoogie.HTTP.Headers.html)
instance. There are used by requests and responses, but can also be used to create the headers
string of the `mail()` command.
HTTP headers are represented by a [Headers][] instance. There are used by requests and
responses, but can also be used to create the headers string of the `mail()` command.



Expand Down Expand Up @@ -828,6 +845,7 @@ ICanBoogie/HTTP is licensed under the New BSD License - See the [LICENSE](LICENS
[DispatchEvent]: http://icanboogie.org/docs/class-ICanBoogie.HTTP.Dispatcher.DispatchEvent.html
[Dispatcher]: http://icanboogie.org/docs/class-ICanBoogie.HTTP.Dispatcher.html
[DispatcherInterface]: http://icanboogie.org/docs/class-ICanBoogie.HTTP.DispatcherInterface.html
[Headers]: http://icanboogie.org/docs/class-ICanBoogie.HTTP.Headers.html
[Response]: http://icanboogie.org/docs/class-ICanBoogie.HTTP.Response.html
[RedirectResponse]: http://icanboogie.org/docs/class-ICanBoogie.HTTP.RedirectResponse.html
[NotFound]: http://icanboogie.org/docs/class-ICanBoogie.HTTP.NotFound.html
Expand Down
4 changes: 0 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@
"psr-4": {
"ICanBoogie\\HTTP\\": "lib/"
},

"classmap": [

"lib/RescueEvent.php"

],

"files": [ "helpers.php" ]
}
}
6 changes: 6 additions & 0 deletions lib/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,17 @@ public function __construct($callable)
$this->callable = $callable;
}

/**
* @inheritdoc
*/
public function __invoke(Request $request)
{
return call_user_func($this->callable, $request);
}

/**
* @inheritdoc
*/
public function rescue(\Exception $exception, Request $request)
{
throw $exception;
Expand Down
4 changes: 2 additions & 2 deletions lib/RedirectResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RedirectResponse extends Response
*
* @throws \InvalidArgumentException if the provided status code is not a redirect.
*/
public function __construct($url, $status=302, array $headers=[])
public function __construct($url, $status = 302, array $headers = [])
{
parent::__construct
(
Expand Down Expand Up @@ -53,7 +53,7 @@ function(Response $response) {
$status, [ 'Location' => $url ] + $headers
);

if (!$this->is_redirect)
if (!$this->status->is_redirect)
{
throw new \InvalidArgumentException("The HTTP status code is not a redirect: {$status}.");
}
Expand Down
Loading

0 comments on commit eb52ded

Please sign in to comment.