Skip to content

Commit

Permalink
Support using App as PSR-15 RequestHandler
Browse files Browse the repository at this point in the history
Implementing the RequestHandlerInterface means the
Slim App is embeddedable to another PSR-15 middleware
stack.
  • Loading branch information
bnf authored and akrabat committed Sep 2, 2018
1 parent d31297c commit 7335aa3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 17 additions & 1 deletion Slim/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Psr\Http\Message\UriInterface;
use Slim\Exception\HttpMethodNotAllowedException;
use Slim\Exception\HttpNotFoundException;
use Psr\Http\Server\RequestHandlerInterface;
use Slim\Http\Headers;
use Slim\Http\Request;
use Slim\Http\Response;
Expand All @@ -34,7 +35,7 @@
* configure, and run a Slim Framework application.
* The \Slim\App class also accepts Slim Framework middleware.
*/
class App
class App implements RequestHandlerInterface
{
use MiddlewareAwareTrait;

Expand Down Expand Up @@ -422,6 +423,21 @@ public function run(RequestInterface $request = null): ResponseInterface
$request = Request::createFromGlobals($_SERVER);
}

return $this->handle($request);
}

/**
* Handle a request
*
* This method traverses the application middleware stack and then returns the
* resultant Response object.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
// create response
$headers = new Headers(['Content-Type' => 'text/html; charset=UTF-8']);
$httpVersion = $this->getSetting('httpVersion');
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"slim/http": ">=0.2",
"psr/http-message": "^1.0",
"nikic/fast-route": "^1.0",
"psr/container": "^1.0"
"psr/container": "^1.0",
"psr/http-server-middleware": "^1.0"
},
"require-dev": {
"pimple/pimple": "^3.2",
Expand Down

0 comments on commit 7335aa3

Please sign in to comment.