getStructure() публичный Метод

Magic constants (__DIR__, __FILE__...) will be resolved to their appropriate value. Scoped class keywords/constants (static::, self::, parent::) will be resolved to their fully qualified name.
public getStructure ( Pinq\Parsing\IFunctionReflection $reflection ) : Pinq\Parsing\IFunctionStructure
$reflection Pinq\Parsing\IFunctionReflection
Результат Pinq\Parsing\IFunctionStructure
Пример #1
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;
     }
 }
Пример #2
0
 /**
  * @param callable $function
  * @param array    $variableTypeMap
  * @param mixed    $expression
  *
  * @return ITypeAnalysis
  */
 protected function getAnalysis(callable $function, array $variableTypeMap = [], &$expression = null)
 {
     $reflection = $this->functionInterpreter->getReflection($function);
     foreach ($reflection->getSignature()->getParameterExpressions() as $parameterExpression) {
         $variableTypeMap[$parameterExpression->getName()] = $this->typeSystem->getTypeFromTypeHint($parameterExpression->getTypeHint());
     }
     $analysisContext = $this->expressionAnalyser->createAnalysisContext($reflection->asEvaluationContext());
     foreach ($variableTypeMap as $variable => $type) {
         $analysisContext->setExpressionType(O\Expression::variable(O\Expression::value($variable)), $type);
     }
     $bodyExpressions = $this->functionInterpreter->getStructure($reflection)->getBodyExpressions();
     foreach ($bodyExpressions as $expression) {
         if ($expression instanceof O\ReturnExpression) {
             return $this->expressionAnalyser->analyse($analysisContext, $expression->getValue());
         } elseif (count($bodyExpressions) === 1) {
             return $this->expressionAnalyser->analyse($analysisContext, $expression);
         } else {
             $this->expressionAnalyser->analyse($analysisContext, $expression);
         }
     }
 }