[8.x] Allow Blade's service injection to inject services typed using class name resolution #36356
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.
Right now, Blade supports service injection via
@inject
directive. Example:Due to the fact that the contents of the expression were parsed/segmented then passed into the
app()
helper but wrapped into quotes, doing something like:Was not possible as the compiled output would be:
$service = app('App\SomeService::class')
resulting in an error. This PR adds the ability to inject services using this syntax, as well as keeping the old syntax. The way it's solved is that, instead of preg_replacing quotes, we'd pass the exact expression into theapp()
helper without wrapping into quotes, while the variable part ($service
) is trimmed of all whitespace as well as quotes.Any breaking changes
The only potentially breaking change I can think of would be if someone accidentally added a whitespace after opening quotation mark:
This would result in calling
app(' App\SomeService')
, while previously this would callapp('App\SomeService')
, but I guess that could be fixed by preg_replacing all whitespace. Let me know.