This repository was archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
Added support for PHP7 \Throwable based exceptions #138
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,9 +56,17 @@ public function onDispatch(MvcEvent $event) | |
$event->setResult($return); | ||
return $return; | ||
} | ||
|
||
$caughtException = null; | ||
try { | ||
$return = $middleware(Psr7Request::fromZend($request), Psr7Response::fromZend($response)); | ||
} catch (\Exception $exception) { | ||
} catch (\Throwable $exception) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above: TODO would be good |
||
$caughtException = $exception; | ||
} catch (\Exception $exception) { // @TODO clean up once PHP 7 requirement is enforced | ||
$caughtException = $exception; | ||
} | ||
|
||
if ($caughtException !== null) { | ||
$event->setName(MvcEvent::EVENT_DISPATCH_ERROR); | ||
$event->setError($application::ERROR_EXCEPTION); | ||
$event->setController($middlewareName); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,7 +184,7 @@ public function prepareExceptionViewModel(MvcEvent $e) | |
if (is_callable($this->message)) { | ||
$callback = $this->message; | ||
$message = (string) $callback($exception, $this->displayExceptions); | ||
} elseif ($this->displayExceptions && $exception instanceof \Exception) { | ||
} elseif ($this->displayExceptions && ($exception instanceof \Exception || $exception instanceof \Throwable)) { // @TODO clean up once PHP 7 requirement is enforced | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you open a related issue on zend-mvc-console, please? This functionality is moved into there for the v3 series. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never mind; I'm working on it now. |
||
$previous = ''; | ||
$previousException = $exception->getPrevious(); | ||
while ($previousException) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,9 +99,17 @@ public function render(MvcEvent $e) | |
$view->setRequest($request); | ||
$view->setResponse($response); | ||
|
||
$caughtException = null; | ||
|
||
try { | ||
$view->render($viewModel); | ||
} catch (\Exception $ex) { | ||
} catch (\Throwable $ex) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
$caughtException = $ex; | ||
} catch (\Exception $ex) { // @TODO clean up once PHP 7 requirement is enforced | ||
$caughtException = $ex; | ||
} | ||
|
||
if ($caughtException !== null) { | ||
if ($e->getName() === MvcEvent::EVENT_RENDER_ERROR) { | ||
throw $ex; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't
Exception
be caught prior toThrowable
? As Exception extends Throwable and would therefore never be caught?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes no difference as the code is the same for
\Exception
and\Throwable
. In PHP 7+ the exceptions or error exceptions are caught by\Throwable
whereas in PHP 5 the exceptions are caught by\Exception
.\Exception
should be removed at some point in the future (wenn PHP5 support is dropped).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a
// @TODO clean up once PHP 7 requirement is enforced
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, just added the todos.