[5.6] Allow using Blade @json statement with arrays or method calls #23655
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.
Introduction
Currently
@jsonwon't be compiled correctly if used with anything else than simple values or variables.This PR allows following:
Backward Compatibility
Above examples would previously result in either syntax errors or calling
json_encodewith incorrect options or depth. Nothing that worked before should break. If you however can think about some odd edge-case that will break I'll be glad to take a look!Details
I added new
BladeCompiler::parseArguments($expression)method, which uses regex to split arguments list given as a string into a flat array. It's rather forgiving and won't complain about syntax errors.This could lead to some non apparent issues when malformed arguments are used. However I decided not to fight an uphill battle and bet for simplicity instead.
If you're inclined to merge this I can add some tests for that method. It could be reused in other
compile*methods or when defining custom directives.