public function offsetSet($key, $newval) { if (isset($this->_counter)) { throw new Mango_Exception('This Mango_Array is acting as a counter'); } if (($key = parent::offsetSet($key, $newval)) !== FALSE) { // new value - remember change $this->_changed[$key] = TRUE; } }
public function offsetSet($index, $newval) { // sets don't have associative keys if (!is_int($index) && !is_null($index)) { throw new Mango_Exception('Mango_Sets only supports numerical keys'); } $mode = is_int($index) && $this->offsetExists($index) ? 'set' : ($this->_duplicates ? 'push' : 'addToSet'); if (isset($this->_mode) && $this->_mode !== $mode) { throw new Mango_Exception('MongoDB cannot :action when already in :mode mode', array(':action' => $mode, ':mode' => $this->_mode)); } if (!$this->_duplicates && $this->find($this->load_type($newval)) !== FALSE) { // value has been added already return TRUE; } // Set value $index = parent::offsetSet($index, $newval); if (is_int($index)) { // value was added successfully, set mode & index of changed value $this->_mode = $mode; $this->_changed[] = $index; } return TRUE; }