diff --git a/Slim/Exception/MethodNotAllowedException.php b/Slim/Exception/MethodNotAllowedException.php index e73b99eeb..a737ab941 100644 --- a/Slim/Exception/MethodNotAllowedException.php +++ b/Slim/Exception/MethodNotAllowedException.php @@ -8,11 +8,26 @@ */ namespace Slim\Exception; +use Exception; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; -class MethodNotAllowedException extends SlimException +class MethodNotAllowedException extends Exception { + /** + * A request object + * + * @var ServerRequestInterface + */ + protected $request; + + /** + * A response object to send to the HTTP client + * + * @var ResponseInterface + */ + protected $response; + /** * HTTP methods allowed * @@ -29,10 +44,31 @@ class MethodNotAllowedException extends SlimException */ public function __construct(ServerRequestInterface $request, ResponseInterface $response, array $allowedMethods) { - parent::__construct($request, $response); + $this->request = $request; + $this->response = $response; $this->allowedMethods = $allowedMethods; } + /** + * Get request + * + * @return ServerRequestInterface + */ + public function getRequest() + { + return $this->request; + } + + /** + * Get response + * + * @return ResponseInterface + */ + public function getResponse() + { + return $this->response; + } + /** * Get allowed methods * diff --git a/Slim/Exception/NotFoundException.php b/Slim/Exception/NotFoundException.php index 8095eaca6..527ba6629 100644 --- a/Slim/Exception/NotFoundException.php +++ b/Slim/Exception/NotFoundException.php @@ -8,7 +8,55 @@ */ namespace Slim\Exception; -class NotFoundException extends SlimException +use \Exception; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; + +class NotFoundException extends Exception { + /** + * A request object + * + * @var ServerRequestInterface + */ + protected $request; + + /** + * A response object to send to the HTTP client + * + * @var ResponseInterface + */ + protected $response; + + /** + * Create new exception + * + * @param ServerRequestInterface $request + * @param ResponseInterface $response + */ + public function __construct(ServerRequestInterface $request, ResponseInterface $response) + { + $this->request = $request; + $this->response = $response; + } + + /** + * Get request + * + * @return ServerRequestInterface + */ + public function getRequest() + { + return $this->request; + } + /** + * Get response + * + * @return ResponseInterface + */ + public function getResponse() + { + return $this->response; + } } diff --git a/Slim/Exception/SlimException.php b/Slim/Exception/SlimException.php deleted file mode 100644 index 2480d73b1..000000000 --- a/Slim/Exception/SlimException.php +++ /dev/null @@ -1,69 +0,0 @@ -request = $request; - $this->response = $response; - } - - /** - * Get request - * - * @return ServerRequestInterface - */ - public function getRequest() - { - return $this->request; - } - - /** - * Get response - * - * @return ResponseInterface - */ - public function getResponse() - { - return $this->response; - } -} diff --git a/tests/AppTest.php b/tests/AppTest.php index 338f27910..954636a17 100644 --- a/tests/AppTest.php +++ b/tests/AppTest.php @@ -1779,23 +1779,6 @@ public function testRunExceptionNoHandler() $res = $app->run(true); } - public function testRunSlimException() - { - $app = $this->appFactory(); - $app->get('/foo', function ($req, $res, $args) { - return $res; - }); - $app->add(function ($req, $res, $args) { - $res->write("Failed"); - throw new SlimException($req, $res); - }); - $res = $app->run(true); - - $res->getBody()->rewind(); - $this->assertEquals(200, $res->getStatusCode()); - $this->assertEquals("Failed", $res->getBody()->getContents()); - } - /** * @requires PHP 7.0 */