[2.x] Fix ignore generic listeners as view composer #794
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 fixes #793 which would throw a ReflectionException when a non-closure listener is attached to the
composing: ...
,creating: ...
or*
event.This happens when a listener is attached like:
Event::listen('*', 'MyListener@handle')
All view composers/creators are wrapped in a closure, see:
Illuminate\View\Concerns\ManagesEvents@addViewEvent
. That means that we can filter out all listeners that are not a closure when fetching the view composers.Technically it would be possible though to create a view composer like
Event::listen('composing: layouts.master', 'MyListener@compose')
. But since there is a dedicatedView::composer
method I assume that's the prefered and supported way to register view composers? If we would add support for those non-closure listeners that would also mean that all listeners for the*
event will be seen as view composer.