Generates an alias for an entity
@param string $entity
@param array $data
@return string|null
162767
public function generateEntity($entity, array $data)
    {
        $handlers = $this->getHandlers();

        if (isset($handlers[$entity]['mapping']) && isset($handlers[$entity]['pattern'])) {
            $data += array('placeholders' => $handlers[$entity]['mapping']);
            return $this->generate($handlers[$entity]['pattern'], $data);
        }

        return null;
    }
832517
protected function _fieldsAreNull($entity, $source)
    {
        $nulls = 0;
        $schema = $source->getSchema();
        foreach ($this->_fields as $field) {
            if ($schema->getColumn($field) && $schema->isNullable($field) && $entity->get($field) === null) {
                $nulls++;
            }
        }

        return $nulls === count($this->_fields);
    }
1320226
protected function generateBody(Entity $entity)
    {
        $descriptor = $entity->getDescriptor();
        $fields     = $descriptor->getFieldList() ?: [];

        $body[] = '$stream      = $context->getStream();';
        $body[] = '$writer      = $context->getWriter();';
        $body[] = '$sizeContext = $context->getComputeSizeContext();';
        $body[] = null;

        foreach ($fields as $field) {
            $lines = $this->generateRequiredFieldException($entity, $field);
            $body  = array_merge($body, $lines);
        }

        foreach ($fields as $field) {
            $lines = $this->generateFieldCondition($entity, $field);
            $body  = array_merge($body, $lines, [null]);
        }

        $extensionsField = $this->getUniqueFieldName($descriptor, 'extensions');
        $extensionsVar   = '$this->' . $extensionsField;

        $body[] = 'if (' . $extensionsVar . ' !== null) {';
        $body[] = '    ' . $extensionsVar . '->writeTo($context);';
        $body[] = '}';
        $body[] = null;
        $body[] = 'return $stream;';

        return $body;
    }
137459
private function getEntityIdentifierValue($entity)
    {
        $entityMetaData = $this->entityManager->getEntityMetadataRegister()->getEntityMetadata($entity);

        return $entityMetaData ? $entityMetaData->getIdentifierValue() : null;
    }
756787
public function hydrate(array $data, $entity)
    {
        $this->hydrateEntityProperties($entity, $data);
        
        $repository = $this->getRepository();
        $repository->dispatchEvent(ORMEvents::onEntityLoad, new EntityLifecycleEvent($repository, $entity));
        
        return $entity;
    }
1243006
protected function hydrateProperties($entity, $data)
    {
        if (isset($data['attributes']) && is_array($data['attributes'])) {
            $entity = parent::hydrateProperties($entity, $data['attributes']);
        }

        return $entity;
    }
759901
private function getEntityEncryptionKey($entity)
    {
        $encryptedKey = $entity->getKey();

        if ($encryptedKey) {
            $key = $this->decryptSymmetricKey($entity);
        }
        else {
            $key = $this->generateSymmetricKey();

            // Insert the encrypted key in the entity
            $entity->setKey($this->encryptSymmetricKey($key, $entity));
        }

        return $key;
    }
1207977
private function createMapper($entity)
    {
        $mapper = new EntityMapper();
        $mapper->setAdapter(
            $this->adapters->get(
                $this->getAdapterAlias($entity)
            )
        )
            ->setEntityClassName($entity);
        $this->mappers->set($entity, $mapper);
        return $mapper;
    }
1360273
private function formatEntities(array $entities) : string
    {
        $formattedEntities = array_map(function (DistanceMatrixLocation $entry) {
            return $entry->getFormattedLocation();
        }, $entities);
        $formattedEntities = implode('|', $formattedEntities);

        return $formattedEntities;
    }
799198
private function getOriginalEntityData($entity)
    {
        $class = $this->em->getClassMetadata(\get_class($entity));
        $data = $this->uow->getOriginalEntityData($entity);
        if ($class->isVersioned) {
            $versionField = $class->versionField;
            $data[$versionField] = $class->reflFields[$versionField]->getValue($entity);
        }

        return $data;
    }
848572
public function primaryWhere(Entity $entity, $data, $table)
    {
        $primaryKeys = $entity->getRepository()->getCache()->getTablePrimaryKeys($table);

        if (strpos($table, '_i18n')) {
            $primaryKeys = ['id', 'language_id'];
        } elseif (strpos($table, '_p17n')) {
            $primaryKeys = ['id', 'user_group_id'];
        }

        foreach ($primaryKeys as $primaryKey) {
            $this->where('`' . $primaryKey . '`', $data[$primaryKey]);
        }
    }
664394
public static function generateDeleteRequest( Entity $entity ) {
        /* Generate the DeleteRequest message */
        $deleteRequestDOM = new DOMDocument();
        $deleteNode       = $deleteRequestDOM->appendChild( $deleteRequestDOM->createElementNS( 'http://schemas.microsoft.com/xrm/2011/Contracts/Services', 'Delete' ) );
        $deleteNode->appendChild( $deleteRequestDOM->createElement( 'entityName', $entity->logicalName ) );
        $deleteNode->appendChild( $deleteRequestDOM->createElement( 'id', $entity->ID ) );

        /* Return the DOMNode */

        return $deleteNode;
    }
36137
public static function createEntities($entityClass, $dataArray)
    {
        return array_map(function ($data) use ($entityClass) {
            return static::createEntity($entityClass, $data);
        }, $dataArray);
    }
886634
public function transform($entity)
    {
        if (null === $entity) {
            return $entity;
        }

        $accessor = PropertyAccess::createPropertyAccessor();

        return $accessor->getValue($entity, 'id');
    }
444279
public function createFromData(array $data): AbstractEntity
    {
        /** @var AbstractEntity $result */
        $result = $this->factory->create();
        $result->mapFromArray($data);
        return $result;
    }
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;
    }
121489
public static function fromData(array $data)
    {
        $class = get_called_class();
        $isDynamic = is_a($class, DynamicEntity::class, true);

        /** @var static $entity */
        $entity = (new \ReflectionClass($class))->newInstanceWithoutConstructor();

        object_set_properties($entity, $data, $isDynamic);

        if (method_exists($entity, '__construct')) {
            $entity->__construct();
        }

        $entity->markNew(false);

        return $entity;
    }