Skip to content
This repository has been archived by the owner on Nov 13, 2019. It is now read-only.

Commit

Permalink
Added WhoopsMiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
phossa committed Oct 8, 2016
1 parent 8446f98 commit 1ff5834
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
All notable changes to this project will be documented in this file. This
project adheres to [Semantic Versioning](http://semver.org/).

### [2.1.0] 2016-09-27
### [2.1.0] 2016-10-08

- Changed

Expand All @@ -14,4 +14,5 @@ project adheres to [Semantic Versioning](http://semver.org/).

- Added

- 2016-10-08 added `WhoopsMiddlware`
- 2016-09-24 added `TerminateQueue`
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"suggest": {
"phossa2/route": "Allows routing middleware",
"phossa2/di": "Allows PSR compatible container",
"zendframework/zend-diactoros": "Allows using PSR-7 HTTP messages"
"zendframework/zend-diactoros": "Allows using PSR-7 HTTP messages",
"franzl/whoops-middleware": "For pretty error handling using Whoops"
},
"autoload": {
"psr-4": { "Phossa2\\Middleware\\": "src/Middleware/" }
Expand Down
52 changes: 52 additions & 0 deletions src/Middleware/Middleware/WhoopsMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Phossa Project
*
* PHP version 5.4
*
* @category Library
* @package Phossa2\Middleware
* @copyright Copyright (c) 2016 phossa.com
* @license http://mit-license.org/ MIT License
* @link http://www.phossa.com/
*/
/*# declare(strict_types=1); */

namespace Phossa2\Middleware\Middleware;

use Psr\Http\Message\RequestInterface;
use Phossa2\Shared\Base\ObjectAbstract;
use Psr\Http\Message\ResponseInterface;
use Franzl\Middleware\Whoops\WhoopsRunner;
use Phossa2\Middleware\Interfaces\DelegateInterface;
use Phossa2\Middleware\Interfaces\MiddlewareInterface;

/**
* WhoopsMiddleware
*
* Using "franzl/whoops-middleware" for Whoops
*
* @package Phossa2\Middleware
* @author Hong Zhang <phossa@126.com>
* @version 2.1.0
* @since 2.1.0 added
*/
class WhoopsMiddleware extends ObjectAbstract implements MiddlewareInterface
{
/**
* Should be the very first middleware in the queue
*
* {@inheritDoc}
*/
public function process(
RequestInterface $request,
ResponseInterface $response,
DelegateInterface $next = null
) {
try {
return $next->next($request, $response);
} catch (\Exception $e) {
return WhoopsRunner::handle($e, $request);
}
}
}

0 comments on commit 1ff5834

Please sign in to comment.