Skip to content

Conversation

@imbrish
Copy link
Contributor

@imbrish imbrish commented Mar 22, 2018

Introduction

Currently @json won't be compiled correctly if used with anything else than simple values or variables.

This PR allows following:

@json(["foo" => "bar", "abc", 12.34, [1, 2, false]])
@json(Foo::bar("abc", 12.34), JSON_HEX_TAG, 256)

Backward Compatibility

Above examples would previously result in either syntax errors or calling json_encode with 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.

@taylorotwell
Copy link
Member

I don't feel like maintaining and debugging that regex. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants