/** * Merge this operation with a previous operation and return the * resulting operation. * * @param FieldOperation $previous Previous Operation. * * @return FieldOperation * @throws AVException */ 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 AVException('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 AVException */ 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 AVException('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 AVException */ 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 AVException('Operation is invalid after previous operation.'); }