Shanty_Mongo_Document::processChanges PHP Méthode

processChanges() public méthode

Convert data changes into operations
public processChanges ( array $data = [] )
$data array
    public function processChanges(array $data = array())
    {
        foreach ($data as $property => $value) {
            if ($property === '_id') {
                continue;
            }
            if (!array_key_exists($property, $this->_cleanData)) {
                $this->addOperation('$set', $property, $value);
                continue;
            }
            $newValue = $value;
            $oldValue = $this->_cleanData[$property];
            if (MongoDBRef::isRef($newValue) && MongoDBRef::isRef($oldValue)) {
                $newValue['$id'] = $newValue['$id']->__toString();
                $oldValue['$id'] = $oldValue['$id']->__toString();
            }
            if ($newValue !== $oldValue) {
                $this->addOperation('$set', $property, $value);
            }
        }
        foreach ($this->_cleanData as $property => $value) {
            if (array_key_exists($property, $data)) {
                continue;
            }
            $this->addOperation('$unset', $property, 1);
        }
    }