Skip to content

Commit

Permalink
phroute fix
Browse files Browse the repository at this point in the history
  • Loading branch information
webdevlabs committed Apr 4, 2017
1 parent 9643d07 commit 1e962a9
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions system/middlewares/Phroute.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Phroute\Phroute\Dispatcher;
use Phroute\Phroute\Exception\HttpRouteNotFoundException;
use Phroute\Phroute\Exception\BadRouteException;

class Phroute
{
Expand Down Expand Up @@ -37,18 +39,16 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
// WITH PSR7 REQUEST/RESPONSE HANDLERS
try {
$_SESSION['requestURI']=$request->getUri()->getPath();
ob_start();
$this->router->dispatch($request->getMethod(), $request->getUri()->getPath());
$bufferedBody = ob_get_clean();
$response->getBody()->write($bufferedBody);
$response = $this->router->dispatch($request->getMethod(), $request->getUri()->getPath());
$response = $response->withStatus(200);
}
catch (\Phroute\Phroute\Exception\HttpRouteNotFoundException $e) {
$reponse = new \Zend\Diactoros\Response\HtmlResponse($e->getMessage(), 404);
catch (HttpRouteNotFoundException $e) {
return $response->withStatus(404);
// $reponse = new \Zend\Diactoros\Response\HtmlResponse($e->getMessage(), 404);
}
catch (\Phroute\Phroute\Exception\BadRouteException $e) {
$allowedMethods = $routeInfo[1];
$reponse = new \Zend\Diactoros\Response\HtmlResponse($e->getMessage(), 405);
catch (BadRouteException $e) {
return $response->withStatus(405);
// $reponse = new \Zend\Diactoros\Response\HtmlResponse($e->getMessage(), 405);
}
return $next($request, $response);
}
Expand Down

0 comments on commit 1e962a9

Please sign in to comment.