コード例 #1
0
ファイル: IncrementOperation.php プロジェクト: uday21/order
 /**
  * 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.');
 }
コード例 #2
0
ファイル: RemoveOperation.php プロジェクト: uday21/order
 /**
  * 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.');
 }
コード例 #3
0
ファイル: AddUniqueOperation.php プロジェクト: uday21/order
 /**
  * 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.');
 }