Checks to see if an entity has changed using a comparison function

@param object $entity The entity to check for changes
@return bool True if the entity has changed, otherwise false
511153
protected function hasChangedUsingComparisonFunction($entity) : bool
    {
        $objectHashId = spl_object_hash($entity);
        $originalData = $this->objectHashIdsToOriginalData[$objectHashId];

        return !$this->comparators[get_class($entity)]($originalData, $entity);
    }
563722
private function checkHasOneRelation($entity, $relation)
    {
        $objectHashId     = $this->entityRegistry->getObjectHashId($entity);
        $varObjName       = $relation->varObjectName();
        $varReferenceName = $relation->varReferenceName();

        $currentRelation  = $this->getValue($entity, $varObjName);
        $originalRelation = $this->getValue($this->entityRegistry->getOriginal($entity), $varObjName);

        if (empty($currentRelation)) {
            // Current entity has no relation
            if (!empty($originalRelation)) {
                // Original had a relation, so relation was removed
                $this->scheduleForDeletion($originalRelation);
            }

            return;
        }

        // Current entity has a relation
        $currentRelationHash = $this->entityRegistry->getObjectHashId($currentRelation);

        if (isset($this->scheduledForDeletion[$objectHashId]) && $relation->cascadeDelete()) {
            $this->scheduleForDeletion($currentRelation);
        }

        if (empty($originalRelation)) {
            // Original had no relation, so relation was newly created
            $this->scheduleRelationForInsertion($entity, $currentRelation, $varReferenceName);

            return;
        }

        $originalRelationHash = $this->entityRegistry->getObjectHashId($originalRelation);

        if ($currentRelationHash != $originalRelationHash) {
            // Relation was exchanged
            $this->scheduleForDeletion($originalRelation);
            $this->scheduleRelationForInsertion($entity, $currentRelation, $varReferenceName);
        }
    }
825212
public function hasChanges(bool &$changedEntities = null): bool
    {
        foreach ($this->entities as $entity) {
            if ($entity->hasChanges()) {
                $changedEntities = true;

                return true;
            }
        }

        return !empty($this->atomics);
    }
314568
public function isCached( Base $entity, $source = self::PERSISTED )
    {
        switch( $source ) {
            case self::PERSISTED:
                return false !== array_search( $entity, $this->instancesPersisted, true );
            case self::UNPERSISTED:
                return false !== array_search( $entity, $this->instancesUnpersisted, true );
            case self::ALL:
                return $this->isCached( $entity, self::PERSISTED ) || $this->isCached( $entity, self::UNPERSISTED );
        }
        throw new \InvalidArgumentException("Bad source `{$source}` passed to " . __FUNCTION__);
    }
38093
public function flush($entity = null)
    {
        if ($entity !== null) {
            $this->persist($entity);
        }

        return $this->getEntityManager()->flush();
    }
972401
public function contains($entity)
    {
        return $this->unitOfWork->isScheduledForInsert($entity)
            || ($this->unitOfWork->isInIdentityMap($entity) && ! $this->unitOfWork->isScheduledForDelete($entity));
    }
647617
public function checkEntities($entities)
    {
        return array_filter($entities, function ($val) {
            $entityClass = $this->entityClass;
            return ($val instanceof $entityClass);
        });
    }
891495
public function save($entity)
    {
        $query = new Query($entity, false);
        $structure = $this->getEntityStructure($entity);

        if ($entity->_saved) {
            // Update
            $result = $query->update()->set($this->getEntityDataArray($entity))->where(array($structure->primaryColumn->name => $entity->_id))->apply();

            // Update relations
            RelationManager::with($entity)->saveRelations();

            return $result;
        } else {
            // Insert
            $id = $query->insert()->into($structure->tableName)->values($this->getEntityDataArray($entity))->apply();

            if ($id === false) {
                return false; // @codeCoverageIgnore
            }

            // Update relations
            RelationManager::with($entity)->saveRelations();

            // Save ID and state
            $entity->{$structure->primaryColumn->propertyName} = $id;
            $entity->_id = $id;
            $entity->_saved = true;

            return true;
        }
    }
112109
public function update(Entity $entity)
    {
        if (!$this->events->shouldExecute($entity, 'before', 'update')) {
            return false;
        }
        $result = $this->doUpdate($entity);
        $this->events->shouldExecute($entity, 'after', 'update');
        return $result;
    }
66298
public function getValueByEntity($entity)
    {
        if (is_object($entity)) {
            $entity = get_class($entity);
        }

        /** @var ValueProviderInterface $provider */
        foreach ($this->getValues() as $provider) {
            if ($entity === $provider->getEntity()) {
                return $provider;
            }
        }

        return false;
    }
1117043
public function validateEntity($entity)
    {
        $description = $entity->getEntityDescription();

        //if entity is persisted only look at the modified
        //properties
        if ($entity->isModified()) {
            $properties = array_intersect_key($description->getProperty(), AnConfig::unbox($entity->getModifiedData()));
        } else {
            $properties = $description->getProperty();
        }

        foreach ($properties as $property) {
            $value = $entity->get($property->getName());
            $entity->getValidator()->validateData($entity, $property, $value);
        }

        return $entity->getErrors()->count() === 0;
    }
891851
public function refresh ($entity)
    {
        // Return if not saved and not in database.
        if (! $entity->_saved) return false;
        $structure = $this->getEntityStructure($entity);

        // ID Data.
        $idColumn = $structure->primaryColumn->name;
        $idValue = $entity->_id;

        if ($structure->primaryColumn->type === 'integer')
            $idValue = intval($idValue);

        // Clear Relationship Cache.
        $entity::clearCache();

        // Query for refreshing.
        $query = new Query($entity);
        $newEntity = $query->select()
            ->where($idColumn, $idValue)
            ->one();

        // If no entity is found (when refreshing).
        if (! $newEntity) return false;

        // Map to the old instance
        foreach ($structure->columns as $column) {
            $entity->{$column->propertyName} = $newEntity->{$column->propertyName};
        }

        return true;
    }
1273080
public function isEntity( &$entity = null )
    {
        if( isset( $this->data['entity'] ) ) {
            $entity = $this->data['entity'];
            return true;
        }
        $entity = null;
        return false;
    }
770939
public function simpleUpdate($entity){
        $simpleUpdate = new SimpleUpdate($entity,$this->getConfig());
        return $this->update($simpleUpdate);
    }
1161965
private function isDoctrineEntity($entity)
    {
        if ($this->annotationReader->isOrm($entity) || $this->annotationReader->isOdm($entity)) {
            return true;
        }

        return false;
    }
1104845
public function is_changed($property = null)
	{
		$properties = static::properties();
		$relations = static::relations();
		$property = (array) $property ?: array_merge(array_keys($properties), array_keys($relations));

		foreach ($property as $p)
		{
			if (isset($properties[$p]))
			{
				if (array_key_exists($p, $this->_original))
				{
					if ((array_key_exists('type', $properties[$p]) and $properties[$p]['type'] == 'int') or
						(array_key_exists('data_type', $properties[$p]) and $properties[$p]['data_type'] == 'int'))
					{
						if ($this->{$p} != $this->_original[$p])
						{
							return true;
						}
					}
					elseif ($this->{$p} !== $this->_original[$p])
					{
						return true;
					}
				}
				else
				{
					if (array_key_exists($p, $this->_data))
					{
						return true;
					}
				}
			}
			elseif (isset($relations[$p]))
			{
				if ($relations[$p]->singular)
				{
					if (empty($this->_original_relations[$p]) !== empty($this->_data_relations[$p])
						or ( ! empty($this->_original_relations[$p])
							and $this->_original_relations[$p] !== $this->_data_relations[$p]->implode_pk($this->{$p})))
					{
						return true;
					}
				}
				else
				{
					if (empty($this->_original_relations[$p]))
					{
						if ( ! empty($this->_data_relations[$p]))
						{
							return true;
						}
						continue;
					}

					$orig_rels = $this->_original_relations[$p];
					foreach ($this->{$p} as $rk => $r)
					{
						if ( ! in_array($r->implode_pk($r), $orig_rels))
						{
							return true;
						}
						unset($orig_rels[array_search($rk, $orig_rels)]);
					}
					if ( ! empty($orig_rels))
					{
						return true;
					}
				}
			}
			else
			{
				throw new \OutOfBoundsException('Unknown property or relation: '.$p);
			}
		}

		return false;
	}
910429
public function moveUp($entity) {
		extract($this->_config);
		$prev = $model::find('first', [
			'conditions' => [
				$parent => $entity->$parent,
				$right => $entity->$left - 1
			]
		]);
		if (!$prev) {
			return true;
		}
		$spanToZero = $entity->$right;
		$rangeX = ['floor' => $entity->$left, 'ceiling' => $entity->$right];
		$shiftX = ($prev->$right - $prev->$left) + 1;
		$rangeY = ['floor' => $prev->$left, 'ceiling' => $prev->$right];
		$shiftY = ($entity->$right - $entity->$left) + 1;

		$this->_updateBetween($rangeX, '-', $spanToZero, $this->_scope($entity));
		$this->_updateBetween($rangeY, '+', $shiftY, $this->_scope($entity));
		$this->_updateBetween([
			'floor' => (0 - $shiftY), 'ceiling' => 0
		], '+', $spanToZero - $shiftX, $this->_scope($entity));

		$entity->set([
			$left => $entity->$left - $shiftX, $right => $entity->$right - $shiftX
		]);
		return true;
	}