@param $entity

@return null|DoplioDbTable
965941
protected function getInstanceFromIdentityMap($entity)
    {
        foreach ($this->identityMap as $item) {
            if (is_array($item[0])) {
                continue;
            }
            if ($item[1] === $entity) {
                return $item[0];
            }
        }

        return null;
    }
227127
public function deleteTranslationData($entity)
    {
        $metadata = $this->metadataCollection->getMetadata($entity);
        if($metadata === null) {
            return null;
        }

        $strategies = $this->strategyResolver->getStrategies();
        foreach($strategies as $strategy) {
            $strategy->deleteTranslationData($entity, $metadata);
        }
    }
174779
public function load(Entity $entity)
    {
        $data = $entity->getRawData();
        if (!is_array($data) || !isset($data[$this->getForeignKey()])) {
            return null;
        }
        /** @var Select $sql */
        $sql = call_user_func_array(
            [$this->getRelatedEntity(), 'find'],
            []
        );
        $pmk = Entity\Manager::getInstance()->get($this->getRelatedEntity())
            ->getEntity()->getPrimaryKey();
        $table = Entity\Manager::getInstance()->get($this->getRelatedEntity())
            ->getEntity()->getTableName();
        $sql-> where(
            [
                "{$table}.{$pmk} = :id" => [
                    ':id' => $data[$this->getForeignKey()]
                ]
            ]
        );
        return $sql->first();
    }
899822
private function getContentFromEntity( $entity ) {
		switch ( $entity->getType() ) {
			case Item::ENTITY_TYPE:
				return new ItemContent( $entity );
			case Property::ENTITY_TYPE:
				return new PropertyContent( $entity );
			default:
				throw new RuntimeException( 'I cant get a content for this type of entity' );
		}
	}
479209
public function persist(Entity $entity)
    {
        $this->checkEntityType($entity);

        $this->events->invokeCallbacks(Events::EVENT_BEFORE_PERSIST, $entity);
        if ($entity->isDetached()) {
            $entity->makeAlive($this->entityFactory, $this->connection, $this->mapper);
            $this->events->invokeCallbacks(Events::EVENT_BEFORE_CREATE, $entity);
            $result = $id = $this->insertIntoDatabase($entity);
            $entity->attach($id);
            $this->events->invokeCallbacks(Events::EVENT_AFTER_CREATE, $entity);
        } else {
            if ($entity->isModified()) {
                $this->events->invokeCallbacks(Events::EVENT_BEFORE_UPDATE, $entity);
                $result = $this->updateInDatabase($entity);
                $this->events->invokeCallbacks(Events::EVENT_AFTER_UPDATE, $entity);
            }
            $this->persistHasManyChanges($entity);
            $entity->markAsUpdated();
        }
        $this->events->invokeCallbacks(Events::EVENT_AFTER_PERSIST, $entity);

        return isset($result) ? $result : null;
    }
138561
public function getModelName($entity) {
        $classRef = new \ReflectionClass($entity);
        $classModelAnnotation = $this->annoReader->getClassAnnotation($classRef, 'Tpg\ExtjsBundle\Annotation\Model');
        if ($classModelAnnotation !== null) {
            if ($classModelAnnotation->name) {
                return $classModelAnnotation->name;
            } else {
                return str_replace("\\", ".", $classRef->getName());
            }
        }
        return null;
    }
234225
public function getPositionFieldByEntity($entity)
    {
        if (is_object($entity)) {
            $entity = ClassUtils::getClass($entity);
        }

        if (isset($this->positionField['entities'][$entity])) {
            return $this->positionField['entities'][$entity];

        } else {
            return $this->positionField['default'];
        }
    }
466297
public function get($entity)
    {
        $key = $this->mapping['fieldname'];
        $valueMethod = 'get' . ucfirst($key);
        $value = $entity->$valueMethod();

        return $value;
    }
924539
public function getRepository($entity)
    {
        $annotation = $this->getClassAnnotation($entity, self::DOCUMENT_CLASS);

        if ($annotation instanceof Document) {
            return $annotation->repository;
        }

        return '';
    }
1076569
public function mapEntity(Entity $entity) {
		$entity['_loc'] = $this->_table->getUrl($entity);
		$entity['_lastmod'] = $entity->{$this->_config['lastmod']};
		$entity['_changefreq'] = $this->_config['changefreq'];
		$entity['_priority'] = $this->_config['priority'];

		return $entity;
	}
1242719
public function getSingleIdentifierValue($entity)
    {
        $class = $this->em->getClassMetadata(get_class($entity));

        if ($class->isIdentifierComposite) {
            throw ORMInvalidArgumentException::invalidCompositeIdentifier();
        }

        $values = $this->isInIdentityMap($entity)
            ? $this->getEntityIdentifier($entity)
            : $class->getIdentifierValues($entity);

        return isset($values[$class->identifier[0]]) ? $values[$class->identifier[0]] : null;
    }
1298058
public function getEntityClassName($entity)
    {
        if (array_key_exists($entity, $this->entityMap)) {
            return $this->entityMap;
        }

        return $this->rootEntityNamespace . $entity;
    }
157022
protected function resolveEntityClass($entity)
    {
        // We first check if the entity is traversable and we'll resolve
        // the entity based on the first item of the object.
        if ($this->isTraversable($entity)) {
            if (!count($entity)) {
                throw new \InvalidArgumentException('Length of Entity collection must be greater than 0');
            }

            $firstEntityItem = ($entity instanceof \Iterator)
                ? $entity->current()
                : current($entity);

            return $this->resolveEntityClass($firstEntityItem);
        }

        if (is_object($entity)) {
            return get_class($entity);
        }

        if (is_string($entity)) {
            return $entity;
        }

        throw new \InvalidArgumentException('Invalid entity type');
    }
649483
protected function storeEntity($entity)
    {
        $this->checkEntityType($entity);

        $store = new Store($this->aggregate($entity), $this->newQueryBuilder());

        return $store->execute();
    }
985453
protected function insertIntoDatabase(Entity $entity)
    {
        $primaryKey = $this->mapper->getPrimaryKey($this->getTable());
        $values = $entity->getModifiedRowData();
        $this->connection->query(
            'INSERT INTO %n %v',
            $this->getTable(),
            $values
        );
        return isset($values[$primaryKey]) ? $values[$primaryKey] : $this->connection->getInsertId();
    }
961091
public function solveFetch(Entity &$entity)
    {
        /** @var JoinTable $joinTable */
        $joinTable = $this->relation->join;

        // Get target entity structure
        $targetStructure = EntityManager::getInstance()->getEntityStructure($joinTable->targetEntityName);

        $query = "SELECT * FROM {$targetStructure->tableName} as target, {$joinTable->name} as couple WHERE target.{$joinTable->targetColumn->entityColumn} = couple.{$joinTable->targetColumn->name} AND couple.{$joinTable->column->name} = ?;";

        $bind = array($entity->{$joinTable->column->entityColumn});
        $results = EntityManager::query($this->relation->targetEntity)->custom($query, $bind);

        return $results;
    }
131651
private function process($entity)
    {
        $entityClass = get_class($entity);

        if (false === ($entity instanceof HasOptionalFieldsEntityInterface)) {
            return false;
        }

        $reflectionClass = new \ReflectionClass($entityClass);
        foreach ($reflectionClass->getProperties() as $reflectionProperty) {
            /** @var Optional $propertyAnnotation */
            $propertyAnnotation = $this->getReader()->getPropertyAnnotation($reflectionProperty, Optional::class);
            if (null === $propertyAnnotation) {
                continue;
            }

            $default = $this->getDefault($reflectionProperty, $propertyAnnotation->default);
            $reflectionProperty->setAccessible(true);

            if (null === $reflectionProperty->getValue($entity)) {
                $reflectionProperty->setValue($entity, $default);
            }
        }

        return true;
    }