Gets an entity instance.

@param array  $data     The instance data.
@param string $dqlAlias The DQL alias of the entity's class.

@return object The entity.

@throws HydrationException
330233
private function getEntity(array $data, $dqlAlias)
    {
        $className = $this->_rsm->aliasMap[$dqlAlias];

        if (isset($this->_rsm->discriminatorColumns[$dqlAlias])) {
            $fieldName = $this->_rsm->discriminatorColumns[$dqlAlias];

            if ( ! isset($this->_rsm->metaMappings[$fieldName])) {
                throw HydrationException::missingDiscriminatorMetaMappingColumn($className, $fieldName, $dqlAlias);
            }

            $discrColumn = $this->_rsm->metaMappings[$fieldName];

            if ( ! isset($data[$discrColumn])) {
                throw HydrationException::missingDiscriminatorColumn($className, $discrColumn, $dqlAlias);
            }

            if ($data[$discrColumn] === "") {
                throw HydrationException::emptyDiscriminatorValue($dqlAlias);
            }

            $discrMap = $this->_metadataCache[$className]->discriminatorMap;

            if ( ! isset($discrMap[$data[$discrColumn]])) {
                throw HydrationException::invalidDiscriminatorValue($data[$discrColumn], array_keys($discrMap));
            }

            $className = $discrMap[$data[$discrColumn]];

            unset($data[$discrColumn]);
        }

        if (isset($this->_hints[Query::HINT_REFRESH_ENTITY]) && isset($this->rootAliases[$dqlAlias])) {
            $this->registerManaged($this->_metadataCache[$className], $this->_hints[Query::HINT_REFRESH_ENTITY], $data);
        }

        $this->_hints['fetchAlias'] = $dqlAlias;

        return $this->_uow->createEntity($className, $data, $this->_hints);
    }
747523
public static function hydrate(array $data)
    {
        return new self(
            $data['token'],
            $data['table'],
            KeySet::fromArray($data['keySet']),
            $data['columns'],
            $data['options']
        );
    }
271072
public function create($data)
	{
		// @todo: Implement processing
		$processPayload = new Payload($data, Payload::STATUS_VALID); // @todo: Super temporary WIP

		// // Process data given.
		// $processPayload = $this->process(__FUNCTION__, $data);

		// if( ! $processPayload->isStatus(Payload::STATUS_VALID))
		// {
		// 	return $processPayload;
		// }

		// Create the entity with the given data.
		$aggregatePayload = $this->aggregate[self::getEntityType()]->create($processPayload->getData());

		// No need to procede if dynamic content was not created.
		if( ! $aggregatePayload->isStatus(Payload::STATUS_CREATED))
		{
			return $aggregatePayload;
		}

		// Create the newly created entity's EntityIdentifier.
		$identifierPayload = $this->createIdentifier($aggregatePayload->getData());

		if( ! $identifierPayload->isStatus(Payload::STATUS_CREATED))
		{
			return $identifierPayload;
		}

		// @todo: The following currently adds an additional query just for the ease of getting the full entity to return.
		$createdEntityPayload = $this->getOneByUuid($aggregatePayload->getData()->getUuid());

		if( ! $createdEntityPayload->isStatus(Payload::STATUS_FOUND))
		{
			return $createdEntityPayload;
		}

		return new Payload($createdEntityPayload->getData(), $aggregatePayload->getStatus());
	}
749342
public function toCollection($data): ICollection
	{
		if ($data instanceof QueryBuilder) {
			return new DbalCollection($this, $this->connection, $data);

		} elseif (is_array($data)) {
			$storageReflection = $this->getStorageReflection();
			$result = array_map([$this->getRepository(), 'hydrateEntity'], array_map([$storageReflection, 'convertStorageToEntity'], $data));
			return new ArrayCollection($result, $this->getRepository());

		} elseif ($data instanceof Result) {
			$result = [];
			$repository = $this->getRepository();
			$storageReflection = $this->getStorageReflection();
			foreach ($data as $row) {
				$result[] = $repository->hydrateEntity($storageReflection->convertStorageToEntity($row->toArray()));
			}
			return new ArrayCollection($result, $this->getRepository());
		}

		throw new InvalidArgumentException('DbalMapper can convert only array|QueryBuilder|Result to ICollection.');
	}
851237
protected function entityToArray($entity, HydratorInterface $hydrator = null)
    {
        if (is_array($entity)) {
            return $entity; // cut down on duplicate code
        } elseif (is_object($entity)) {
            if (!$hydrator) {
                $hydrator = $this->getHydrator();
            }
            return $hydrator->extract($entity);
        }
        throw new Exception\InvalidArgumentException('Entity passed to db mapper should be an array or object.');
    }
306638
public static function getOrCreate(array $data, Entity $entity = null)
    {
        $record = static::gets($data, $entity);

        if (!$record) {
            $record = static::create($data, $entity);
        }

        return $record;
    }
724416
public function create($data) {
		$dt = $this->getDataTable();
		
		if (! $dt)
			return $this->createResponse($this->getNameManager()->getTableNames(), 401, "Tabels");
		
		return $this->createResponse([], 200, "{$this->getNameManager()->entityName}: No Create");
	}
863810
public function create(array $data = [])
    {
        $account = new Account();

        if (array_key_exists('avatar', $data)) {
            $account->setAvatar(
                $this->getAvatarFactory()->createCollection($data['avatar'])
            );
        }

        return $this->hydrate($account, $data);
    }
1340612
protected function hydrate($entity, array $arguments)
    {
        foreach ($arguments as $argument => $value) {
            if (is_array($value)) {
                if(isset($this->em->getClassMetadata(get_class($entity))->associationMappings[$argument])) {
                    $value = $this->hydrateRelation($entity, $argument, $value);
                }
            }
            $entity->{"set".Inflector::camelize($argument)}($value);
        }

        return $entity;
    }
1141256
protected function hydrateAssociations($entity, $data)
    {
        if (isset($data['relationships']) && is_array($data['relationships'])) {
            $metadata = $this->entityManager->getClassMetadata(get_class($entity));

            foreach ($data['relationships'] as $name => $data) {
                if (!isset($metadata->associationMappings[$name])) {
                    throw new \Exception(sprintf('Relation `%s` association not found', $name));
                }

                $mapping = $metadata->associationMappings[$name];

                if (is_array($data['data'])) {
                    if ($resourceId = $this->getResourceId($data['data'])) {
                        $this->hydrateToOneAssociation($entity, $name, $mapping, $resourceId);
                    } else {
                        $this->hydrateToManyAssociation($entity, $name, $mapping,
                            $this->mapRelationshipsArray($data['data'])
                        );
                    }
                }
            }
        }

        return $entity;
    }
894784
private function hydrateMany(string $classPath, array $data): Collection
    {
        $collection = new Collection();
        foreach ($data as $entityData) {
            /** @var Hydratable $entity */
            $entity = new $classPath();
            $entity->hydrate($entityData);

            $collection->append($entity);
        }

        return $collection;
    }
148639
public function initByData( array $data = null )
    {

        if( !$data ) {
            return null;
        }

        // table inheritance - ghetto?
        /*
        if( isset( $data['tableoid'] ) ) {
            if( $data['tableoid'] != static::OID ) {
                $repo = Repository::init( $data['tableoid'] );
                return $repo->initByData( $data );
            }
            unset( $data['tableoid'] );
        }
        */

        $key = call_user_func(
            array( $this->entityClass, 'keyGet' ),
            $data
        );

        // is this already in the cache? Are we initalising something we've already loaded?
        if( isset( $this->instancesPersisted[$key] ) ) {

            // Late loading? Don't need this anymore.
            $obj = $this->instancesPersisted[$key];
            $obj->__construct( $data );
            return $obj;

        }

        $obj = parent::initByData($data);
        $this->instancesPersisted[$key] = $obj;

        return $obj;

    }
621482
public function getFilter(QueryBuilder $qb, $dqlAlias)
    {
        $spec = $this->getSpec();
        if ($spec instanceof Filter) {
            return $spec->getFilter($qb, $this->getAlias($dqlAlias));
        }

        return;
    }
1325491
private function hydrateToManyRelation($entity, $name, $targetEntity, $data, $scope)
    {
        if (!is_array($data)) {
            throw RestException::missingData($scope);
        }

        $this->setObjectProperty($entity, $name,
            new ArrayCollection(array_map(
                function($item, $index) use ($targetEntity, $scope) {
                    return $this->hydrateRelationData($targetEntity, $item, $scope.'['.$index.']');
                },
                $data,
                array_keys($data)
            ))
        );
    }
927969
public function dataToEntity(array $data)
    {
        $cartItem = new \ShopgateExternalCoupon();
        foreach ($data as $key => $value) {
            $method = 'set' . SimpleDataObjectConverter::snakeCaseToUpperCamelCase($key);
            if (method_exists($cartItem, $method)) {
                $cartItem->{$method}($value);
            }
        }

        return $cartItem;
    }
844752
public function hydrate(EntityInterface $entity, array $entityData)
    {
        $this->getHydrator()->hydrate($entityData, $entity);
        
        return $this;
    }
252556
public function make( array $data = null )
    {

        if( !$this->makeableSafetyCheck() ) {
            return null;
        }

        $entity = $this->entityFactory();
        if( $data !== null ) {
            $entity->set(
                $data,
                // as data is a array the second argument doesn't make much sense here
                null,
                // set the inital values and see that the correct input validation happens
                $entity->inputValidate
             );
        }
        return $entity;

    }