[Feature request] New variables #16
Open
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.
Hello.
First of all, thank you for this project.
Secondly, this is not PR, but some thoughts on the new look of JsonLogic.
Callable $data
Sometimes we need dynamic data using sql/cache/etc
Static variables/iterations + some sugar
The problem with
var
logic is recursions likesome
,reduce
, etc. This is due to the fact that we overwrite data, e.g:https://github.com/jwadhams/json-logic-php/blame/e4ea3a46f44d3d34740276f7a21f8f052b029743/src/JWadhams/JsonLogic.php#L263-L267C15
We have lost the original
$data
, but sometimes we need access to it.Example. My post has some tags, such as:
["php", "js", "webdev", "docker"]
, I want to group all cloud posts into a separate category. For searching I want to use logic like:Right now we can't access the original $data in recursion.
Here's what I suggest.
Add new logic for the
$var
keys (likevar
) and$iteration
to look like this:(in sample i use sugar for
"$iteration"
, it can be used similarly:["$iteration"]
,["$iteration" => null]
, etc)Why i think it is best solution:
Problem/Todo
$iteration
only at current level, I think we should make access to upper levels of$iteration
.What does the community think about this?