Author: Elliot Levin (elliotlevin@hotmail.com)
Inheritance: extends Expression
コード例 #1
0
 public function walkVariable(VariableExpression $expression)
 {
     $name = $expression->getName();
     if ($name instanceof O\ValueExpression) {
         return $expression->update(O\Expression::value($this->prefix . $name->getValue()));
     }
     return $expression->update(O\Expression::binaryOperation(O\Expression::value($this->prefix), O\Operators\Binary::CONCATENATION, $name));
 }
コード例 #2
0
 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);
 }
コード例 #3
0
ファイル: ExpressionAnalyser.php プロジェクト: timetoogo/pinq
 public function visitVariable(O\VariableExpression $expression)
 {
     $nameExpression = $expression->getName();
     $this->walk($nameExpression);
     $type = $this->analysisContext->getExpressionType($expression);
     if ($type === null) {
         throw new TypeException('Invalid variable expression: \'%s\' type is unknown', $nameExpression->compileDebug());
     }
     $this->analysis[$expression] = $type;
 }
コード例 #4
0
ファイル: MiscExpressionTest.php プロジェクト: timetoogo/pinq
 public function testExpressionNameType()
 {
     $this->assertSame(O\BinaryOperationExpression::getExpressionTypeName(), 'BinaryOperation');
     $this->assertSame(O\VariableExpression::getExpressionTypeName(), 'Variable');
     $this->assertSame(O\Expression::getExpressionTypeName(), '');
 }
コード例 #5
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;
     }
 }