/** * Get the attributes that have been modified since * the entity have been fetched from the database * * @return array */ public function getDirtyAttributes() { $attributes = $this->flattenEmbeddables($this->entity->getEntityAttributes()); $id = $attributes[$this->keyName]; $cachedAttributes = $this->mapper->getEntityCache()->get($id); $dirty = []; foreach ($attributes as $key => $value) { if ($this->isRelation($key) || $key == 'pivot') { continue; } if (!array_key_exists($key, $cachedAttributes) && !$value instanceof Pivot) { $dirty[$key] = $value; } elseif ($value !== $cachedAttributes[$key] && !$this->originalIsNumericallyEquivalent($value, $cachedAttributes[$key])) { $dirty[$key] = $value; } } return $dirty; }
protected function cachedArray(Mappable $entity) { // Flatten Value Objects as attributes $attributes = $this->flattenEmbeddables($entity->getEntityAttributes()); $cache = []; foreach ($attributes as $key => $value) { if ($value instanceof ProxyInterface) { continue; } if ($value instanceof Mappable) { $class = get_class($value); $mapper = Manager::getMapper($class); $keyName = $mapper->getEntityMap()->getKeyName(); $cache[$key] = new CachedRelationship($class . '.' . $value->{$keyName}, $this->getPivotValues($key, $value)); continue; } if ($value instanceof EntityCollection) { $cache[$key] = []; foreach ($value as $relatedEntity) { $hash = $this->getEntityHash($relatedEntity); $cache[$key][$hash] = new CachedRelationship($hash, $this->getPivotValues($key, $relatedEntity)); } continue; } $cache[$key] = $value; } return $cache; }