json-logic-php icon indicating copy to clipboard operation
json-logic-php copied to clipboard

Updated to support various array conditions

Open mjnewman opened this issue 7 years ago • 1 comments

Hello! Very impressed by JSON Logic – It works exceptionally well. Great work!

I added a few operators for evaluating array conditions. These seem to be working well for my needs and I wanted to submit them as a pull request.

Hopefully these are helpful and, if so, can be incorporated. Thanks for your time and consideration!

mjnewman avatar Aug 11 '16 20:08 mjnewman

Hey, sorry if you're getting weird cross notifications, I've never seen that happen between repos before.

This looks like good functionality to add with two caveats:

  1. Would it be possible for you to create some unit tests? If you run phpunit it'll download the shared tests from jsonlogic.com into tests/tests.json. You can append to the bottom. The basic format is that the whole file is an array. Comments are strings, and tests are an array of rule, data, expected outcome. I can use the unit tests to build the matching functionality in the JS library. In PHP every rule gets run twice, once with json_decode using PHP associative arrays, and once using PHP objects.
  2. I'm starting to think about having some light weight name spaces around functionality groups. The original idea came from this issue https://github.com/jwadhams/json-logic-js/issues/3 but I think it would make the library easier to grok even for new "native" functionality. So something like renaming these functions array.compare and array.key_exists ? (That would suggest I should alias or rename the functions array.merge and array.in)

jwadhams avatar Aug 16 '16 15:08 jwadhams