Adding compatibility with symfony/expression-language

Adding the ability to process string expressions using the
symfony/expression-language. It keeps backward compatibility to the
provided operators and with any new operator defined using the default
mechanism.

One upside down with this approach is that you can have a full object
inside the context and evaluate on its attributes using a symfony
expression.
Okay, we have 2 issues here:

1. We can't guarantee the given expression will return a boolean. So just
returning the response from the evaluation seems wrong to me.
2. We can't validate the expression before evaluating it. So we might have
exceptions in `holdsFor`.

The first issue can be solved by checking the returned value of the
evaluation. At least to make sure we return a boolean, or maybe by casting
the result to a boolean (which can cause weird behauvior)

The second is tricky and I think we should skip that for later.
On 24 Oct 2014 23:07, "jorgelbg" <notifications@github.com> wrote:

> In lib/Qandidate/Toggle/ExpressionCondition.php:
>
> > +    /**
> > +     * @param string $expression The expression to ve evaluated
> > +     */
> > +    function __construct($expression)
> > +    {
> > +        $this->expression = $expression;
> > +        $this->language   = new ExpressionLanguage();
> > +    }
> > +
> > +
> > +    /**
> > +     * @inheritdoc
> > +     */
> > +    public function holdsFor(Context $context)
> > +    {
> > +        return $this->language->evaluate($this->expression, $context->toArray());
>
> The ExpressionLanguage doesn't provide a validation per se, basically
> when the expression gets parsed the validation is done inside the Parser
> class, if an error is found, a SyntaxError exception gets thrown (with a
> hint message) but this only happens when the expression is evaluated.
>
> A couple of problems: there is no way of "validating" or syntax checking
> the expression before evaluation happens. One work around could be to parse
> the expression first (into PHP code) using the parse method in the
> ExpressionCondition constructor (the context keys are required for this
> operation) an then just evaluate this code on the holdsFor method. This
> way it's kind of ok despite of the requirement of the Context keys added
> to the class constructor.
>
> The other way could be to catch the SyntaxError on the holdsFor() method
> and default to false, leaving the decision to the rest of the conditions in
> the same Toggle. Or just report this exception back to the user if it
> gets thrown.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/qandidate-labs/qandidate-toggle/pull/7/files#r19364604>
> .
>