Author: Elliot Levin (elliot@aanet.com.au)
Inheritance: use trait Storm\Core\Helpers\Type
 public function __construct(Object\PropertyData $PropertyData)
 {
     parent::__construct($PropertyData->GetEntityType());
     foreach ($PropertyData as $PropertyIdentifier => $Value) {
         $Property = $PropertyData->GetProperty($PropertyIdentifier);
         $this->AddPredicate(Expression::BinaryOperation(Expression::Property($Property), Operators\Binary::Identity, Expression::Constant($Value)));
     }
 }
Exemple #2
0
 private function ParseOperatorNode(\PHPParser_Node_Expr $Node, $NodeType)
 {
     switch (true) {
         case isset(self::$AssignOperatorsMap[$NodeType]):
             return Expression::Assign($this->ParseNodeInternal($Node->var), self::$AssignOperatorsMap[$NodeType], $this->ParseNodeInternal($Node->expr));
         case isset(self::$BinaryOperatorsMap[$NodeType]):
             return Expression::BinaryOperation($this->ParseNodeInternal($Node->left), self::$BinaryOperatorsMap[$NodeType], $this->ParseNodeInternal($Node->right));
         case isset(self::$UnaryOperatorsMap[$NodeType]):
             return Expression::UnaryOperation(self::$UnaryOperatorsMap[$NodeType], $this->ParseNodeInternal($Node->expr));
         case isset(self::$CastOperatorMap[$NodeType]):
             return Expression::Cast(self::$CastOperatorMap[$NodeType], $this->ParseNodeInternal($Node->expr));
         default:
             return null;
     }
 }
 protected final function MapExpression(Mapping\IEntityRelationalMap $EntityRelationalMap, O\Expression $Expression)
 {
     /* @var $ExpressionMapper RR\IExpressionMapper */
     $ExpressionMapper = $this->GetDatabase()->GetPlatform()->GetExpressionMapper();
     switch (true) {
         case $Expression instanceof O\PropertyExpression:
             return array_map([Expression::GetType(), 'ReviveColumn'], $EntityRelationalMap->GetMappedReviveColumns($Expression->GetProperty()));
         case $Expression instanceof O\ConstantExpression:
             return [$ExpressionMapper->MapConstantExpression($Expression->GetValue())];
         case $Expression instanceof O\ObjectExpression:
             if (!$Expression->HasInstance()) {
                 throw new Mapping\MappingException('Cannot map object expression without a valid object instance.');
             }
             return [$ExpressionMapper->MapObjectExpression($Expression->GetClassType(), $Expression->GetInstance())];
         case $Expression instanceof O\PropertyFetchExpression:
             $ObjectExpression = $Expression->GetObjectExpression();
             return [$ExpressionMapper->MapPropertyFetchExpression($Expression->IsStatic() ? null : $this->MapExpression($EntityRelationalMap, $ObjectExpression)[0], $Expression->GetClassType(), $Expression->GetName())];
         case $Expression instanceof O\MethodCallExpression:
             $ObjectExpression = $Expression->GetObjectExpression();
             return [$ExpressionMapper->MapMethodCallExpression($Expression->IsStatic() ? null : $this->MapExpression($EntityRelationalMap, $ObjectExpression)[0], $Expression->GetClassType(), $Expression->GetName(), array_map(function ($Expression) use(&$EntityRelationalMap) {
                 return $this->MapExpression($EntityRelationalMap, $Expression)[0];
             }, $Expression->GetArgumentValueExpressions()))];
         case $Expression instanceof O\ArrayExpression:
             return [Expression::ValueList(array_map(function ($Expression) use(&$EntityRelationalMap) {
                 return $this->MapExpression($EntityRelationalMap, $Expression)[0];
             }, $Expression->GetValueExpressions()))];
             //Limitation: only one to one mapping for some expressions
         //Limitation: only one to one mapping for some expressions
         case $Expression instanceof O\AssignmentExpression:
             $ColumnExpressions = array_map([Expression::GetType(), 'Column'], $EntityRelationalMap->GetMappedPersistColumns($Expression->GetProperty()));
             $Operator = $this->OperatorMapper->MapAssignmentOperator($Expression->GetOperator());
             $SetValueExpression = $this->MapExpression($EntityRelationalMap, $Expression->GetRightOperandExpression())[0];
             return array_map(function ($ColumnExpression) use(&$ExpressionMapper, &$Operator, &$SetValueExpression) {
                 return $ExpressionMapper->MapAssignmentExpression($ColumnExpression, $Operator, $SetValueExpression);
             }, $ColumnExpressions);
         case $Expression instanceof O\BinaryOperationExpression:
             return [$ExpressionMapper->MapBinaryOperationExpression($this->MapExpression($EntityRelationalMap, $Expression->GetLeftOperandExpression())[0], $this->OperatorMapper->MapBinaryOperator($Expression->GetOperator()), $this->MapExpression($EntityRelationalMap, $Expression->GetRightOperandExpression())[0])];
         case $Expression instanceof O\UnaryOperationExpression:
             return [$ExpressionMapper->MapUnaryOperationExpression($this->OperatorMapper->MapUnaryOperator($Expression->GetOperator()), $this->MapExpression($EntityRelationalMap, $Expression->GetOperandExpression())[0])];
         case $Expression instanceof O\CastExpression:
             return [$ExpressionMapper->MapCastExpression($this->OperatorMapper->MapCastOperator($Expression->GetCastType()), $this->MapExpression($EntityRelationalMap, $Expression->GetCastValueExpression())[0])];
         case $Expression instanceof O\FunctionCallExpression:
             return [$ExpressionMapper->MapFunctionCallExpression($Expression->GetName(), array_map(function ($Expression) use(&$EntityRelationalMap) {
                 return $this->MapExpression($EntityRelationalMap, $Expression)[0];
             }, $Expression->GetArgumentValueExpressions()))];
         case $Expression instanceof O\TernaryExpression:
             return [$ExpressionMapper->MapIfExpression($this->MapExpression($EntityRelationalMap, $Expression->GetConditionExpression())[0], $this->MapExpression($EntityRelationalMap, $Expression->GetIfTrueExpression())[0], $this->MapExpression($EntityRelationalMap, $Expression->GetIfFalseExpression())[0])];
         default:
             throw new Mapping\MappingException('Unsupported object expression type %s given', get_class($Expression));
     }
 }