Prepare event handlers for Laravel 5.4 #47
Merged
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.
This pull request prepares
sentry-laravelfor the upcoming Laravel 5.4 release.There are two changes that affect this package, as I described here:
Dispatcher::firing()method has been removed and instead the event name is passed as the first argument.illuminate.logevent has been changed toIlluminate\Log\Events\MessageLogged.For the second change, I simply added another handler.
First change however was a bit more tricky. Because of changed event handling I was left with two options:
I chose the second one, simply because it provides cleaner and more easily extendable logic.
There are three events which need handling. For each of them there is an old and a new version, therefore there are total of 6 events with handlers attached:
Because wildcard events essentially went through one method, there was no problem with catching all exceptions thrown by handlers. Now however, as each event has it's own method there would be
try-catchblock duplication all over the class. In order to avoid that, I don't register actual handler in the Dispatcher, instead I register a fictional method, a call to which is intercepted by__callmethod, handling all exceptions and passing the event payload down to the actual handler.I have tested these changes in Laravel 5.1, 5.2, 5.3 and 5.4 with following bit of code:
An
undefined variableerror was caugth by Sentry and in the Issue summary there was the correct route as well as log entry and SQL query.5.0 doesn't support PHP 7 and isn't supported by Laravel team, so I didn't run any tests there. Also Laravel event logic hasn't been changed between 5.0 and 5.1 so all code that works with 5.1 should also work with 5.0.