Skip to content

Commit

Permalink
fixed process
Browse files Browse the repository at this point in the history
  • Loading branch information
JanHuang committed May 16, 2017
1 parent e6b9d24 commit 1e5f451
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace FastD\Middleware;


use FastD\Http\Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

Expand All @@ -29,11 +30,27 @@ abstract public function handle(ServerRequestInterface $request, DelegateInterfa
/**
* @param ServerRequestInterface $request
* @param DelegateInterface $next
* @return ResponseInterface
* @return Response|mixed|ResponseInterface
* @throws \Exception
*/
public function process(ServerRequestInterface $request, DelegateInterface $next)
{
return $this->handle($request, $next);
try {
$return = call_user_func_array([$this, 'handle'], [$request, $next]);
if ($return instanceof ResponseInterface) {
$response = $return;
$return = '';
} else {
$response = new Response();
}
$body = $response->getBody();
if (!empty($return) && $body->isWritable()) {
$body->write($return);
}
return $response;
} catch (\Exception $exception) {
throw $exception;
}
}

/**
Expand Down

0 comments on commit 1e5f451

Please sign in to comment.