Skip to content

Commit

Permalink
Value operation methods return $this for chain operations
Browse files Browse the repository at this point in the history
  • Loading branch information
juvenn committed Oct 26, 2015
1 parent 02a80d7 commit f3301d9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/LeanCloud/LeanObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function getUpdatedAt() {
* Set field value by key.
* @param string $key field key
* @param mixed $val field value
* @return void
* @return $this
* @throws RuntimeException
*/
public function set($key, $val) {
Expand All @@ -187,16 +187,18 @@ public function set($key, $val) {
$val = new SetOperation($key, $val);
}
$this->_applyOperation($val);
return $this;
}

/**
* Delete field by key.
*
* @param string $key Field key
* @return void
* @return $this
*/
public function delete($key) {
$this->_applyOperation(new DeleteOperation($key));
return $this;
}

/**
Expand All @@ -223,9 +225,11 @@ public function get($key) {
*
* @param string $key field key
* @param number $amount amount to increment
* @return $this
*/
public function increment($key, $amount = 1) {
$this->_applyOperation(new IncrementOperation($key, $amount));
return $this;
}

/**
Expand Down Expand Up @@ -267,37 +271,40 @@ private function _applyOperation($operation) {
*
* @param string $key Field key
* @param miexed $val Object to add
* @return void
* @return $this
* @throws RuntimeException When adding to non-array field
*/
public function add($key, $val) {
$this->_applyOperation(new ArrayOperation($key, array($val), "Add"));
return $this;
}

/**
* Add one object into array field only if it is not already present.
*
* @param string $key Field key
* @param mixed $val Object to add
* @return void
* @return $this
* @throws RuntimeException When adding to non-array field
*/
public function addUnique($key, $val) {
$this->_applyOperation(new ArrayOperation($key,
array($val),
"AddUnique"));
return $this;
}

/**
* Remove one object from array field.
*
* @param string $key Field key
* @param mixed $val Object to remove
* @return void
* @return $this
* @throws RuntimeException When removing from non-array field
*/
public function remove($key, $val) {
$this->_applyOperation(new ArrayOperation($key, array($val), "Remove"));
return $this;
}

/**
Expand Down

0 comments on commit f3301d9

Please sign in to comment.