public function set($selector, $value)
{
$value = self::prepareToStore($value);
// modify
$arraySelector = explode('.', $selector);
$chunksNum = count($arraySelector);
// optimize one-level selector search
if (1 == $chunksNum) {
// update only if new value different from current
if (!isset($this->data[$selector]) || $this->data[$selector] !== $value) {
// modify
$this->data[$selector] = $value;
// mark field as modified
$this->modifiedFields[] = $selector;
}
return $this;
}
// selector is nested
$section =& $this->data;
for ($i = 0; $i < $chunksNum - 1; $i++) {
$field = $arraySelector[$i];
if (!isset($section[$field])) {
$section[$field] = array();
} elseif (!is_array($section[$field])) {
throw new Exception('Assigning sub-document to scalar value not allowed');
}
$section =& $section[$field];
}
// update only if new value different from current
if (!isset($section[$arraySelector[$chunksNum - 1]]) || $section[$arraySelector[$chunksNum - 1]] !== $value) {
// modify
$section[$arraySelector[$chunksNum - 1]] = $value;
// mark field as modified
$this->modifiedFields[] = $selector;
}
return $this;
}
public function bitwiceXor($field, $value) { $oldFieldValue = (int) $this->get($field); $newValue = $oldFieldValue ^ $value; parent::set($field, $newValue); if ($this->getId()) { if (version_compare($this->getCollection()->getDatabase()->getClient()->getDbVersion(), '2.6', '>=')) { $this->operator->bitwiceXor($field, $value); } else { $this->operator->set($field, $newValue); } } return $this; }