Check if the entity is already registered.

@param string|Entity $entity

@return bool
171414
public function isRegisteredEntity($entity)
    {
        if (!is_string($entity)) {
            $entity = get_class($entity);
        }

        return array_key_exists($entity, $this->entityClasses);
    }
422806
public function hasDefaultValue(Entity $entity)
    {
        $descriptor = $entity->getDescriptor();
        $fields     = $descriptor->getFieldList() ?: [];

        foreach ($fields as $field) {
            if ( ! $field->hasDefaultValue()) {
                continue;
            }

            return true;
        }

        return false;
    }
972118
public function isValidEntity($entity) {
    if ($entity->getEntityTypeId() === 'mentions') {
      return TRUE;
    }

    // Special cases for comments and posts.
    $allowed_content_types = [
      'comment',
    ];
    if (in_array($entity->getEntityTypeId(), $allowed_content_types)) {
      $mentions = $this->getMentionsFromRelatedEntity($entity);
      if (!empty($mentions)) {
        return TRUE;
      }
    }
    return FALSE;
  }
1323068
public function beforeSave(Event $event, Entity $entity) {
		if (isset($entity['name'])) {
			$entity['name'] = mb_strtolower($entity['name']);
		}
		if (isset($entity['ext'])) {
			$entity['ext'] = mb_strtolower($entity['ext']);
		}

		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;
    }
736357
public function register($entity)
    {
        if ($entity instanceof QueryEntityAware) {
            $entity = $entity->getQueryEntity();
        }
        if ($entity instanceof QueryEntity) {
            $name = $entity->getName();
            if ($this->has($name)) {
                throw new RuntimeException("Meta with name \"{$name}\" already exists.");
            }
            $this->meta[$name] = $entity;
        } else {
            throw new InvalidArgumentException('Argument must be instanceof QueryEntityAware or QueryEntity.');
        }
    }
274098
protected function registerEntity($entity)
    {
        Orm::getRepository($this->getParentEntity())
            ->getIdentityMap()
            ->set($entity);

        return $entity;
    }
861250
public function persist(AbstractEntity $entity)
    {
        $update = $entity->getId() !== null;

        for ($i = count($this->registries) - 1; $i >= 0; $i--) {
            /** @var RegistryInterface $registry */
            $registry = $this->registries[ $i ];
            if ($update) {
                $registry->update($entity->getId(), $entity);
            } else {
                $registry->add($entity->getId(), $entity);
            }
        }
    }
647617
public function checkEntities($entities)
    {
        return array_filter($entities, function ($val) {
            $entityClass = $this->entityClass;
            return ($val instanceof $entityClass);
        });
    }
488948
public function isManagedByDoctrine($entity)
    {
        $cacheKey  = 'managed';
        $entity    = $this->toString($entity);
        $isManaged = $this->getFromCache($entity, $cacheKey, null);

        if (null !== $isManaged) {
            return $isManaged;
        }

        try {
            $this->managed = $isManaged = (bool) $this->entityManager->getReference($entity, 0);
            $entity = $this->getEntityClassFull($entity);
        } catch (\Exception $e) {
            $isManaged = false;
        }

        $this->cache[$entity][$cacheKey] = $isManaged;

        return $isManaged;
    }
604373
public function delete($entity)
    {
        $query = new Query($entity, false);
        $structure = $this->getEntityStructure($entity);

        if ($entity->_saved) {
            return $query->delete($structure->tableName)->where(array($structure->primaryColumn->name => $entity->_id))->apply();
        }
        return false;
    }
974284
public function isEntityScheduled($entity)
    {
        $oid = spl_object_id($entity);

        return isset($this->entityInsertions[$oid])
            || isset($this->entityUpdates[$oid])
            || isset($this->entityDeletions[$oid]);
    }
1079715
public function beforeSave(Event $event, Entity $entity) {
		if (isset($entity['name'])) {
			$entity['name'] = ucwords($entity['name']);
		}

		return true;
	}
700607
public function save($entity) {
        $this->load();
        $mapper = MapperBuilder::buildFromClassName($this->mapping, get_class($entity));
        if (is_null($entity->getId())) {
            $affectedRows = $this->insertEntity($entity, $mapper);
        } else {
            $affectedRows = $this->updateEntity($entity, $mapper);
        }
        if (0 < $affectedRows) {
            return true;
        } else {
            return false;
        }
    }
568720
public function setEntity(Entity $entity)
    {
        /** @var SharedEventManager $events */
        $events = $this->getContainer()->get('sharedEventManager');
        $events->attach(
            get_class($entity),
            Save::BEFORE_SAVE,
            [$this, 'beforeSave']
        );
        $events->attach(
            get_class($entity),
            Select::BEFORE_SELECT,
            [$this, 'beforeSelect']
        );
        $events->attach(
            get_class($entity),
            Select::AFTER_SELECT,
            [$this, 'afterSelect']
        );
        $this->getContainer()->set('sharedEventManager', $events);
        return parent::setEntity($entity);
    }
1309230
private function isIdentifierEquals($entity1, $entity2)
    {
        if ($entity1 === $entity2) {
            return true;
        }

        $class = $this->em->getClassMetadata(get_class($entity1));

        if ($class !== $this->em->getClassMetadata(get_class($entity2))) {
            return false;
        }

        $oid1 = spl_object_hash($entity1);
        $oid2 = spl_object_hash($entity2);

        $id1 = isset($this->entityIdentifiers[$oid1])
            ? $this->entityIdentifiers[$oid1]
            : $this->identifierFlattener->flattenIdentifier($class, $class->getIdentifierValues($entity1));
        $id2 = isset($this->entityIdentifiers[$oid2])
            ? $this->entityIdentifiers[$oid2]
            : $this->identifierFlattener->flattenIdentifier($class, $class->getIdentifierValues($entity2));

        return $id1 === $id2 || implode(' ', $id1) === implode(' ', $id2);
    }
1212351
public function register($entity, $entityMap = null)
    {
        // If an object is provider, get the class name from it
        if (!is_string($entity)) {
            $entity = get_class($entity);
        }

        if ($this->isRegisteredEntity($entity)) {
            throw new MappingException("Entity $entity is already registered.");
        }

        if (!class_exists($entity)) {
            throw new MappingException("Class $entity does not exists");
        }

        if ($entityMap === null) {
            $entityMap = $this->getEntityMapInstanceFor($entity);
        }

        if (is_string($entityMap)) {
            $entityMap = new $entityMap();
        }

        if (!$entityMap instanceof EntityMap) {
            throw new MappingException(get_class($entityMap).' must be an instance of EntityMap.');
        }

        $entityMap->setClass($entity);

        $this->entityClasses[$entity] = $entityMap;
    }