/** * Merge this operation with a previous operation and return the * resulting operation. * * @param FieldOperation $previous Previous Operation. * * @return FieldOperation * @throws ParseException */ public function _mergeWithPrevious($previous) { if (!$previous) { return $this; } if ($previous instanceof DeleteOperation) { return new SetOperation($this->value); } if ($previous instanceof SetOperation) { return new SetOperation($previous->getValue() + $this->value); } if ($previous instanceof IncrementOperation) { return new IncrementOperation($previous->getValue() + $this->value); } throw new ParseException('Operation is invalid after previous operation.'); }
/** * Takes a previous operation and returns a merged operation to replace it. * * @param FieldOperation $previous Previous operation. * * @return FieldOperation Merged operation. * @throws ParseException */ public function _mergeWithPrevious($previous) { if (!$previous) { return $this; } if ($previous instanceof DeleteOperation) { return $previous; } if ($previous instanceof SetOperation) { return new SetOperation($this->_apply($previous->getValue(), $this->objects, null)); } if ($previous instanceof RemoveOperation) { $oldList = $previous->getValue(); return new RemoveOperation(array_merge((array) $oldList, (array) $this->objects)); } throw new ParseException('Operation is invalid after previous operation.'); }
/** * Merge this operation with the previous operation and return the result. * * @param FieldOperation $previous Previous Operation. * * @return FieldOperation Merged Operation. * @throws ParseException */ public function _mergeWithPrevious($previous) { if (!$previous) { return $this; } if ($previous instanceof DeleteOperation) { return new SetOperation($this->objects); } if ($previous instanceof SetOperation) { $oldValue = $previous->getValue(); $result = $this->_apply($oldValue, null, null); return new SetOperation($result); } if ($previous instanceof AddUniqueOperation) { $oldList = $previous->getValue(); $result = $this->_apply($oldList, null, null); return new AddUniqueOperation($result); } throw new ParseException('Operation is invalid after previous operation.'); }
/** * Perform an operation on an object property. * * @param string $key Key to perform an operation upon. * @param FieldOperation $operation Operation to perform. * * @return null * @ignore */ public function _performOperation($key, FieldOperation $operation) { $oldValue = null; if (isset($this->estimatedData[$key])) { $oldValue = $this->estimatedData[$key]; } $newValue = $operation->_apply($oldValue, $this, $key); if ($newValue !== null) { $this->estimatedData[$key] = $newValue; } else { if (isset($this->estimatedData[$key])) { unset($this->estimatedData[$key]); } } if (isset($this->operationSet[$key])) { $oldOperations = $this->operationSet[$key]; $newOperations = $operation->_mergeWithPrevious($oldOperations); $this->operationSet[$key] = $newOperations; } else { $this->operationSet[$key] = $operation; } $this->dataAvailability[$key] = true; }
/** * Merge this operation with a previous operation and return the new * operation. * * @param FieldOperation $previous Previous operation. * * @return FieldOperation Merged operation result. * * @throws \Exception */ public function _mergeWithPrevious($previous) { if ($previous == null) { return $this; } if ($previous instanceof ParseRelationOperation) { if ($previous->targetClassName != null && $previous->targetClassName != $this->targetClassName) { throw new \Exception('Related object object must be of class ' . $this->targetClassName . ', but ' . $previous->targetClassName . ' was passed in.'); } $newRelationToAdd = self::convertToOneDimensionalArray($this->relationsToAdd); $newRelationToRemove = self::convertToOneDimensionalArray($this->relationsToRemove); $previous->addObjects($newRelationToAdd, $previous->relationsToAdd); $previous->removeObjects($newRelationToAdd, $previous->relationsToRemove); $previous->removeObjects($newRelationToRemove, $previous->relationsToAdd); $previous->addObjects($newRelationToRemove, $previous->relationsToRemove); $newRelationToAdd = self::convertToOneDimensionalArray($previous->relationsToAdd); $newRelationToRemove = self::convertToOneDimensionalArray($previous->relationsToRemove); return new ParseRelationOperation($newRelationToAdd, $newRelationToRemove); } throw new \Exception('Operation is invalid after previous operation.'); }