Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

add ability to pass operator via context #27

Closed
th3fallen opened this issue Nov 3, 2014 · 22 comments
Closed

add ability to pass operator via context #27

th3fallen opened this issue Nov 3, 2014 · 22 comments
Assignees
Labels

Comments

@th3fallen
Copy link

It would be fantastic if i could pass the operator in via the context like the following example

    $ruleString = 'app operator value';

    $context = new Context();
    $context['app'] = $this->critera['app'];
    $context['operator'] = '!=';
    $context['value'] = $rule->value;
@Hywan Hywan added the question label Nov 3, 2014
@Hywan Hywan self-assigned this Nov 3, 2014
@Hywan
Copy link
Member

Hywan commented Nov 3, 2014

What is the advantage compared to using the asserter?

@th3fallen
Copy link
Author

for my preticular usage im trying to use this along with this jquery library http://mistic100.github.io/jQuery-QueryBuilder/ to build rules in a gui so the operator changes regularly for each rule.

@Hywan
Copy link
Member

Hywan commented Nov 3, 2014

I think we have to define a pre-processor in this case. /cc @hoaproject/hoackers Maybe this is a little bit overkill?

@Hywan
Copy link
Member

Hywan commented Nov 3, 2014

I specifically ping @stephpy on this issue since he has started a similar project (the GUI).

@stephpy
Copy link
Member

stephpy commented Nov 4, 2014

Hi,

In this example (of Jquery QueryBuilder), you'll have to define many operators in context, so if i follow you, you'll have to do:

example

$context = new Context();
......
$context['operator0'] = "less";
$context['operator1'] = "equal"

Then, you'll have to edit yours rules to transform to price operator0 "10,25" (or something like that).

This is not readable, and hard do debug ...

BTW, I don't see any benefit to inject operator in Context rather than trasforming operator0 to less.

@th3fallen
Copy link
Author

no, im saving the rules once the user is done into json and then decoding that with php resulting in an object of each rule so i only need one operator, i guess i could do a strreplace on the rule text and replace the word operator with the string version from the rule,

@Hywan
Copy link
Member

Hywan commented Nov 4, 2014

@stephpy You are right, this is why I have proposed a pre-processor. Thoughts?

@stephpy
Copy link
Member

stephpy commented Nov 4, 2014

I guess this is a specific case and we should not introduce this kind of things on Hoa\Ruler.

You could add as you say a strreplace easily on your side.

@th3fallen
Copy link
Author

Thanks for the help though guys.

@stephpy
Copy link
Member

stephpy commented Nov 4, 2014

You're welcome.

@Hywan
Copy link
Member

Hywan commented Nov 4, 2014

@th3fallen Did we answer to your question?

@th3fallen
Copy link
Author

@Hywan Somewhat i believe i can just do the the str_replace and get my desired result.

@Hywan
Copy link
Member

Hywan commented Nov 5, 2014

@th3fallen Another possibility is to add a “callback” function, something like: lambda(operator1, operandLeft, operandRight), and lambda applies operandLeft and operandRight on operator1. Thoughts? It can be standard also.

@th3fallen
Copy link
Author

@Hywan Actually i found it to be easier just to add the operators in the style i needed them using the setOperator method. Works like a charm.

@Hywan
Copy link
Member

Hywan commented Nov 7, 2014

@th3fallen Perfect then :-). Can I ask you to ping us when your project will be finalized? This is a nice usecase!

@th3fallen
Copy link
Author

@Hywan Will do, a question for you though, what version of php is this library ment to be used with. Im noticing that hoa/compiler/Hoa/Compiler/Llk/Parser.php:234 the exception there is not being fired and is showing an error in my ide of "The thrown object must be an instance of the Exception"

@Metalaka
Copy link
Member

Metalaka commented Nov 7, 2014

showing an error in my ide of "The thrown object must be an instance of the Exception"

It's because Hoa\Compiler\Exception is a flex entity and IDEs don't recognize this alias implementation.

@th3fallen
Copy link
Author

@Metalaka When running the application i still get no thrown errors, i actually get no output at all....

@Hywan
Copy link
Member

Hywan commented Nov 8, 2014

@th3fallen Can you open on Hoa\Compiler please?

@janvandijk
Copy link

How far did you come with this use-case? I'm wanting to implement the same kind of functionality

@th3fallen
Copy link
Author

@janvandijk see #27 (comment) i did it using the setOperator method.

@janvandijk
Copy link

Awesome, I did read that comment... was wondering if there were any changes since then.

(Thank you for your reply!) 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

5 participants