public function testExpressionWalkerPassesTheCorrectParametersWithExtendedExpression()
 {
     $expression = new ExtendedExpression(O\Expression::value(0));
     $called = false;
     $expressionWalker = new O\DynamicExpressionWalker([O\VariableExpression::getType() => function ($walkedExpression, $calledWalker) use($expression, &$called, &$expressionWalker) {
         $called = true;
         $this->assertSame($expression, $walkedExpression);
         $this->assertSame($expressionWalker, $calledWalker);
     }]);
     $expressionWalker->walk($expression);
     $this->assertTrue($called);
 }
Esempio n. 2
0
 protected function parseQueryExpression(callable $queryFunction, O\IEvaluationContext &$evaluationContext = null)
 {
     $reflection = $this->functionInterpreter->getReflection($queryFunction);
     $evaluationContext = $reflection->asEvaluationContext();
     $function = $this->functionInterpreter->getStructure($reflection);
     $expressions = $function->getBodyExpressions();
     $this->assertCount(1, $expressions);
     //Resolve the parameter variable with the queryable value and $this
     $parameterName = $reflection->getSignature()->getParameterExpressions()[0]->getName();
     $expression = $expressions[0];
     foreach ([$parameterName => $this->queryable, 'this' => $this] as $variable => $value) {
         $variableReplacer = new O\DynamicExpressionWalker([O\VariableExpression::getType() => function (O\VariableExpression $expression) use($variable, &$value) {
             if ($expression->getName() instanceof O\ValueExpression && $expression->getName()->getValue() === $variable) {
                 return O\Expression::value($value);
             } else {
                 return $expression;
             }
         }, O\ClosureExpression::getType() => function ($closure) {
             return $closure;
         }]);
         $expression = $variableReplacer->walk($expression);
     }
     if ($expression instanceof O\ReturnExpression) {
         return $expression->getValue();
     } else {
         return $expression;
     }
 }