@param $entities array Entities to be stored as objects.
@param $entityId string ID to be used in generating map.
@param $entityClass string Class of entities.

@return array Map mapping entity identifier to the entity.
193263
public static function generateMap($entities, $entityId, $entityClass)
    {
        $entityMap = [];
        foreach ($entities as $entity) {
            if ($entity instanceof $entityClass) {
                $entityObject = $entity;
            } else {
                $entityObject = new $entityClass;
                foreach ($entity as $key => $value) {
                    $propSetter = 'set'.ucfirst($key);
                    if (method_exists($entityObject, $propSetter)) {
                        $entityObject->$propSetter($value);
                    }
                }
            }

            if (is_null($entityId)) {
                array_push($entityMap, $entityObject);
            } else {
                $propKeyGetter = 'get'.ucfirst($entityId);
                $entityMap[$entityObject->$propKeyGetter()] = $entityObject;
            }
        }

        return $entityMap;
    }
423443
public function entities($entityClassMapperClassMap)
    {
        foreach ($entityClassMapperClassMap as $entity => $mapper) {
            $this->entity($entity)->from($mapper);
        }
    }
443665
public function getCustomerAttributesByEntityId($entityId)
    {

        // initialize the array for the attributes
        $attributes = array();

        // load the datetime attributes
        foreach ($this->customerDatetimeRepository->findAllByEntityId($entityId) as $attribute) {
            $attributes[$attribute[MemberNames::ATTRIBUTE_ID]] = $attribute;
        }

        // load the decimal attributes
        foreach ($this->customerDecimalRepository->findAllByEntityId($entityId) as $attribute) {
            $attributes[$attribute[MemberNames::ATTRIBUTE_ID]] = $attribute;
        }

        // load the integer attributes
        foreach ($this->customerIntRepository->findAllByEntityId($entityId) as $attribute) {
            $attributes[$attribute[MemberNames::ATTRIBUTE_ID]] = $attribute;
        }

        // load the text attributes
        foreach ($this->customerTextRepository->findAllByEntityId($entityId) as $attribute) {
            $attributes[$attribute[MemberNames::ATTRIBUTE_ID]] = $attribute;
        }

        // load the varchar attributes
        foreach ($this->customerVarcharRepository->findAllByEntityId($entityId) as $attribute) {
            $attributes[$attribute[MemberNames::ATTRIBUTE_ID]] = $attribute;
        }

        // return the array with the attributes
        return $attributes;
    }
816663
public function getRepository($entityClass)
    {
        $container = $this->getContainer();

        $em = $container->get('doctrine')->getManager();

        /* @var EntityRepository $repository */
        return $em->getRepository($entityClass);
    }
461539
public function documentToEntity($document, string $entityClassName)
    {
        if (!$this->annotationParser->isEntityClass($entityClassName)) {
            return $document;
        }

        try {
            $reflectClass = new \ReflectionClass($entityClassName);
        } catch (\Exception $exception) {
            return $document;
        }

        $entity = new $entityClassName();

        foreach ($reflectClass->getProperties() as $documentProperty) {
            if ($documentProperty->isStatic()) {
                continue;
            }

            $annotation = $this->annotationParser->getPropertyAnnotation($documentProperty);
            if (null === $annotation) {
                continue;
            }

            $propertyName = $annotation->name ?? $documentProperty->getName();
            if ($annotation->id) {
                $propertyName = '_id';
            }
            $propertyValue = $document->{$propertyName} ?? null;
            $fieldValue = $this->propertyToField($propertyValue, $annotation);

            $documentProperty->setAccessible(true);
            $documentProperty->setValue($entity, $fieldValue);
        }

        return $entity;
    }
1265438
public function entityIdsFrom(IEntitySet $entities) : ObjectArrayFieldBuilder
    {
        return (new ObjectArrayFieldBuilder($this
            ->type(new ArrayOfObjectIdsType(
                $entities,
                Field::element()->entityIdFrom($entities)->required()->build()
            ))
        ))->containsNoDuplicates();
    }
176726
public function castToEntity($matches, $entityClass)
    {
        $entityRegistry = $this->repositoryFactory->getEntityRegistry();

        $result = [];

        $meta        = $this->getMeta($entityClass);
        $entityClass = $meta->class;
        $reflection  = new \ReflectionClass($entityClass);

        foreach ($matches as $match) {
            $entity = new $entityClass;

            foreach ($meta->fields as $key => $definition) {
                /** @var Element $definition */
                $varName = $definition->propertyName($key);
                $colName = $definition->columnName($key);

                $value = isset($definition->default) ? $definition->default : null;

                if (array_key_exists($colName, $match)) {
                    // @todo Apply validation according to definition
                    $value = $match[$colName];

                    if ($definition instanceof Field) {
                        switch ($definition->type) {
                            case 'int':
                            case 'integer':
                                $value = (integer)$value;
                                break;

                            case 'json':
                                $value = json_decode($value);
                                break;

                            default:
                                // Leave the value alone
                                break;
                        }
                    }
                }

                if ($reflection->hasProperty($varName)) {
                    $property = $reflection->getProperty($varName);
                    $property->setAccessible(true);
                    $property->setValue($entity, is_null($value) ? $entity->{$varName} : $value);
                } else {
                    /** @noinspection PhpVariableVariableInspection */
                    $entity->{$varName} = $value;
                }
            }

            $entityRegistry->stashEntity($entity);
            $this->resolveRelations($entity, $meta);
            $entityRegistry->registerEntity($entity);

            $result[] = $entity;

            unset($entity);
        }

        return $result;
    }
474443
private function getSlugMapItems($entityClass, $entityId, array $properties = [])
    {
        return $this->getSlugMapItemRepository()->getByEntityBuilder($entityClass, $entityId, $properties)->getQuery()->getResult();
    }
317437
public function mapEntities(array $entityDefinitions)
	{
		foreach($entityDefinitions as $entityIdentifier => $entityDefinition)
		{
			$this->validateAndCompleteEntity($entityIdentifier, $entityDefinition);
		}
	}
548712
private function getNewObjectFlagMeta($entityClass)
    {
        $meta = $this->extendedMetadataFactory->getExtendedMetadata($entityClass);

        return isset($meta['newObjectFlag']) ? $meta['newObjectFlag'] : [];
    }
218746
private function createDataMapper($entityClass)
    {
        /** @var DataMapperInterface $dataMapper */
        $dataMapperClass = isset($this->config['dataMapper']) ? $this->config['dataMapper'] : DoctrineDataMapper::class;

        $meta = $this->builder->getMeta($entityClass);

        if ($meta->storage['type'] == 'api') {
            $dataMapperClass = $meta->storage['handler'];
        }

        switch ($dataMapperClass) {
            case CsvDataMapper::class:
                $connectionClass = CsvDataGateway::class;

                break;

            default:
                $connectionClass = Connection::class;

                break;
        }

        $dataMapper = new $dataMapperClass(
            $this->getConnection($connectionClass),
            $entityClass,
            $meta->storage['table'],
            $this->entityRegistry
        );

        if ($dataMapper instanceof DispatcherAwareInterface) {
            $dataMapper->setDispatcher($this->getDispatcher());
        }

        return $dataMapper;
    }
1157953
@SuppressWarnings("unchecked")
  @Override
  public <T> List<T> getCollection(Class<T> entityClass) {
    String collectionName = Util.determineCollectionName(entityClass);
    Map<Object, T> collection = (Map<Object, T>) collectionsRef.get().get(collectionName);
    if (null == collection) {
      createCollection(collectionName);
      collection = (Map<Object, T>) collectionsRef.get().get(collectionName);
    }

    CollectionMetaData cmd = cmdMap.get(collectionName);
    List<T> newCollection = new ArrayList<T>();
    try {
      for (T document : collection.values()) {
        Object obj = Util.deepCopy(document);
        if(encrypted && cmd.hasSecret() && null != obj) {
          CryptoUtil.decryptFields(obj, cmd, dbConfig.getCipher());
        }
        newCollection.add((T) obj);
      }
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
      logger.error("Error when decrypting value for a @Secret annotated field for entity: " + collectionName, e);
      throw new JsonDBException("Error when decrypting value for a @Secret annotated field for entity: " + collectionName, e);
    }
    return newCollection;
  }
765135
public function getIdentityMap(string $entityType) : IdentityMap
    {
        if (!isset($this->identityMaps[$entityType])) {
            $this->identityMaps[$entityType] = new IdentityMap($entityType);
        }

        return $this->identityMaps[$entityType];
    }
1372019
public function getEntityGenerator( PgClass $pgclass, array $options, $entityFileStore )
    {

        // build entity
        $tags = $this->getNormalityTags();

        $generators = array(
            'Entity' => '\Bond\Normality\Generate\Entity',
            'Link' => '\Bond\Normality\Generate\Entity\Link',
            'Child' => '\Bond\Normality\Generate\Entity\Child',
        );

        if( isset( $tags['entity'] ) ) {
            $entity = $tags['entity'];
        } elseif ( $parent = $this->get('parent') ) {
            $entity = 'Child';
        } else {
            $entity = 'Entity';
        }

        foreach( $generators as $key => $generator ) {

            if( in_array( strtolower( $entity ), array( strtolower( $key ), strtolower( $generator ) ) ) ) {

                $ref = new \ReflectionClass( $generator );
                return $ref->newInstance( $this, $db, $options, $entityFileStore );

            }

        }

        throw new \RuntimeException( "No generator found for `{entity}` and relation `{$this->get('name')}`" );

    }
1231113
public function setEntityArguments($entityClass, array $arguments)
    {
        $this->entityArguments[$this->getEntityClass($entityClass)] = $arguments;
        return $this;
    }
445818
public function delete($entityId)
    {
        $this->preDelete($entityId);
        $return = $this->doDelete($entityId);
        $this->postDelete($entityId);

        return $return;
    }
686604
public function findByIds($class, array $ids)
    {
        if (count($ids) === 0) {
            return array();
        }

        $dql = "SELECT object FROM {$class} object WHERE object.id IN (:ids)";
        $query = $this->wrapped->createQuery($dql);
        $query->setParameter('ids', $ids);
        $objects = $query->getResult();

        if (($entityCount = count($objects)) !== ($idCount = count($ids))) {
            throw new MissingObjectException(
                "{$entityCount} out of {$idCount} ids don't match any existing object"
            );
        }

        return $objects;
    }