Adds the metadata required to encrypt the doctrine entity

@param DoctrineClassMetadata $metadata
@return DoctrineClassMetadata
433187
public function addEncryptionMetadata(DoctrineClassMetadata $metadata)
    {
        if ($metadata->isMappedSuperclass) {
            return;
        }

        $reflection = $metadata->getReflectionClass();
        if ($this->hasEncryptionEnabled($reflection) && !$this->hasEncryptionFieldsDoctrineMetadata($metadata)) {
            $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT);
            if ($this->keyPerEntityRequired($reflection)) {
                // Add the field required to hold the key used to encrypt this entity
                $keyField = array(
                    'fieldName' => 'key',
                    'columnName' => '_key',
                    'type' => 'object',
                    'nullable' => true,
                );
                $metadata->mapField($keyField);

                // Add the field required to hold the initialization vector used to encrypt this entity
                $ivField = array(
                    'fieldName' => 'iv',
                    'columnName' => '_iv',
                    'type' => 'text',
                    'nullable' => true,
                );
                $metadata->mapField($ivField);
            }

            // Field to control is the entity is already encrypted or not
            $isEncryptedField = array(
                'fieldName' => 'encrypted',
                'columnName' => '_encrypted',
                'type' => 'boolean',
            );
            $metadata->mapField($isEncryptedField);

            // Field to force the persitence of the entity in the migration process
            $isMigratedField = array(
                'fieldName' => 'migrated',
                'columnName' => '_migrated',
                'type' => 'boolean',
            );
            $metadata->mapField($isMigratedField);

            // Add a field to check if the associated file is encrypted
            if ($this->hasFileEncryptionEnabled($reflection)) {
                $isFileEncryptedField = array(
                    'fieldName' => 'fileEncrypted',
                    'columnName' => '_file_encrypted',
                    'type' => 'boolean',
                );
                $metadata->mapField($isFileEncryptedField);
            }
        }

        if ($this->hasEncryptionEnabled($reflection)) {
            // Modify the metadata of the encrypted fields of the entity
            $encryptedFields = $this->getEncryptionEnabledFields($reflection);
            foreach ($encryptedFields as $encryptedField) {
                $fieldName = $encryptedField->name;
                $fieldMapping = $metadata->getFieldMapping($fieldName);
                // We process the field if has not already been process in another class of the hierarchy
                if (!isset($fieldMapping['_old_type'])) {
                    $encryptedFieldMapping = $this->getEncryptedFieldMapping($fieldMapping);
                    $override = $encryptedFieldMapping->getMappingAttributeOverride();
                    /*
                     * It's not possible to change the type of a column using
                     * Doctrine\ORM\Mapping\ClassMetadata::setAssociationOverride
                     * The only alternative that I found it to directly access the fieldMappings property
                     * that until the version 2.5 of Doctrine ORM is public. If this changes in comming
                     * versions of Doctrine this should also be changed
                     */
                    $metadata->fieldMappings[$fieldName] = $override;
                }
            }
        }

        return $metadata;
    }
1196111
public function addMetaData(array $metadata)
    {
        $this->metaData = array_replace_recursive($this->metaData, $metadata);
        $this->metaData = $this->removeNullElements($this->metaData);

        return $this;
    }
744362
public function setMetadata(string $metadata): self
    {
        $this->isValidString($metadata, 1000);

        $this->metadata = $metadata;

        return $this;
    }
126554
private function sanitizeMetadatas($metadata = null)
    {
        if (!$metadata) {
            $metadata = $this->em->getMetadataFactory()->getAllMetadata();
        }
        usort($metadata, function ($a, $b) {
            /** @var ClassMetadata $a */
            /** @var ClassMetadata $b */
            return strcmp($a->getName(), $b->getName());
        });
        return $metadata;
    }
601850
protected function getInstance(ClassMetadata $metadata)
    {
        $reflection = new ReflectionClass($metadata->getName());
        $instance   = $reflection->newInstanceWithoutConstructor();

        return $instance;
    }
47082
public function add_metadata(array $metadata, $rcpt = null)
	{
		if (is_null($rcpt))
		{
			$this->metadata = $metadata;
		}
		else
		{
			$this->rcpt_metadata[$rcpt] = $metadata;
		}

		return $this;
	}
437078
function loadMetadataForClass($className, ClassMetadata $metadata)
    {
        $moduleOptions = \SoliantEntityAudit\Module::getModuleOptions();
        $entityManager = $moduleOptions->getEntityManager();
        $metadataFactory = $entityManager->getMetadataFactory();
        $builder = new ClassMetadataBuilder($metadata);

        if ($className == 'SoliantEntityAudit\\Entity\RevisionEntity') {
            $builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
            $builder->addManyToOne('revision', 'SoliantEntityAudit\\Entity\\Revision', 'revisionEntities');
            $builder->addField('entityKeys', 'string');
            $builder->addField('auditEntityClass', 'string');
            $builder->addField('targetEntityClass', 'string');
            $builder->addField('revisionType', 'string');
            $builder->addField('title', 'string', array('nullable' => true));

            $metadata->setTableName($moduleOptions->getRevisionEntityTableName());
            return;
        }

        // Revision is managed here rather than a separate namespace and driver
        if ($className == 'SoliantEntityAudit\\Entity\\Revision') {
            $builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
            $builder->addField('comment', 'text', array('nullable' => true));
            $builder->addField('timestamp', 'datetime');

            // Add association between RevisionEntity and Revision
            $builder->addOneToMany('revisionEntities', 'SoliantEntityAudit\\Entity\\RevisionEntity', 'revision');

            // Add assoication between User and Revision
            $userMetadata = $metadataFactory->getMetadataFor($moduleOptions->getUserEntityClassName());
            $builder
                ->createManyToOne('user', $userMetadata->getName())
                ->addJoinColumn('user_id', $userMetadata->getSingleIdentifierColumnName())
                ->build();

            $metadata->setTableName($moduleOptions->getRevisionTableName());
            return;
        }

#        $builder->createField('audit_id', 'integer')->isPrimaryKey()->generatedValue()->build();
        $identifiers = array();
#        $metadata->setIdentifier(array('audit_id'));

        //  Build a discovered many to many join class
        $joinClasses = $moduleOptions->getJoinClasses();
        if (in_array($className, array_keys($joinClasses))) {

            $builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();

            $builder->addManyToOne('targetRevisionEntity', 'SoliantEntityAudit\\Entity\\RevisionEntity');
            $builder->addManyToOne('sourceRevisionEntity', 'SoliantEntityAudit\\Entity\\RevisionEntity');

            $metadata->setTableName($moduleOptions->getTableNamePrefix() . $joinClasses[$className]['joinTable']['name'] . $moduleOptions->getTableNameSuffix());
//            $metadata->setIdentifier($identifiers);
            return;
        }


        // Get the entity this entity audits
        $metadataClassName = $metadata->getName();
        $metadataClass = new $metadataClassName();

        $auditedClassMetadata = $metadataFactory->getMetadataFor($metadataClass->getAuditedEntityClass());

        $builder->addManyToOne($moduleOptions->getRevisionEntityFieldName(), 'SoliantEntityAudit\\Entity\\RevisionEntity');
# Compound keys removed in favor of auditId (audit_id)
        $identifiers[] = $moduleOptions->getRevisionEntityFieldName();

        // Add fields from target to audit entity
        foreach ($auditedClassMetadata->getFieldNames() as $fieldName) {
            $builder->addField($fieldName, $auditedClassMetadata->getTypeOfField($fieldName), array('nullable' => true, 'quoted' => true));
            if ($auditedClassMetadata->isIdentifier($fieldName)) $identifiers[] = $fieldName;
        }

        foreach ($auditedClassMetadata->getAssociationMappings() as $mapping) {
            if (!$mapping['isOwningSide']) continue;

            if (isset($mapping['joinTable'])) {
                continue;
            }

            if (isset($mapping['joinTableColumns'])) {
                foreach ($mapping['joinTableColumns'] as $field) {
                    $builder->addField($mapping['fieldName'], 'integer', array('nullable' => true, 'columnName' => $field));
                }
            } elseif (isset($mapping['joinColumnFieldNames'])) {
                foreach ($mapping['joinColumnFieldNames'] as $field) {
                    $builder->addField($mapping['fieldName'], 'integer', array('nullable' => true, 'columnName' => $field));
                }
            } else {
                throw new \Exception('Unhandled association mapping');
            }

        }

        $metadata->setTableName($moduleOptions->getTableNamePrefix() . $auditedClassMetadata->getTableName() . $moduleOptions->getTableNameSuffix());
        $metadata->setIdentifier($identifiers);

        return;
    }
972006
protected function generateEntityAnnotation(ClassMetadataInfo $metadata)
    {
        $prefix = '@' . $this->annotationsPrefix;

        if ($metadata->isEmbeddedClass) {
            return $prefix . 'Embeddable';
        }

        $customRepository = $metadata->customRepositoryClassName
            ? '(repositoryClass="' . $metadata->customRepositoryClassName . '")'
            : '';

        return $prefix . ($metadata->isMappedSuperclass ? 'MappedSuperclass' : 'Entity') . $customRepository;
    }
1053680
public function loadClassMetadata(Mapping\ClassMetadataInterface $metadata)
    {
        
        $reflClass = $metadata->getReflectionClass();
        
        //Iterate over properties to get annotations
        foreach($reflClass->getProperties() as $property) {
            
            $this->readProperty($property, $metadata);
            
        }
        
    }
570115
protected function generateEntityDocBlock(ClassMetadataInfo $metadata)
    {
        $lines = array();
        $lines[] = '/**';
        $lines[] = ' * ' . $this->getClassName($metadata);

        if ($this->generateAnnotations) {
            $lines[] = ' *';

            $methods = array(
                'generateTableAnnotation',
                'generateInheritanceAnnotation',
                'generateDiscriminatorColumnAnnotation',
                'generateDiscriminatorMapAnnotation',
                'generateEntityAnnotation',
            );

            foreach ($methods as $method) {
                if ($code = $this->$method($metadata)) {
                    $lines[] = ' * ' . $code;
                }
            }

            if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) {
                $lines[] = ' * @' . $this->annotationsPrefix . 'HasLifecycleCallbacks';
            }
        }

        $lines[] = ' */';

        return implode("\n", $lines);
    }
1324260
protected function generateEntityClassName(ClassMetadataInfo $metadata)
    {
        return 'class ' . $this->getClassName($metadata) .
        ($this->extendsClass() ? ' extends ' . $this->getClassToExtendName() : null) .
        ($this->interfaceClass() ? ' implements ' . $this->getClassToInterfaceName() : null);
    }
598848
private function mapTranslatable(ClassMetadata $metadata)
    {
        // In the case A -> B -> TranslatableInterface, B might not have mapping defined as it
        // is probably defined in A, so in that case, we just return.
        if (!isset($this->configs[$metadata->name])) {
            return;
        }

        $metadata->mapOneToMany([
            'fieldName'     => 'translations',
            'targetEntity'  => $this->configs[$metadata->name],
            'mappedBy'      => 'translatable',
            'fetch'         => ClassMetadataInfo::FETCH_EXTRA_LAZY,
            'indexBy'       => 'locale',
            'cascade'       => ['persist', 'merge', 'refresh', 'remove'],
            'orphanRemoval' => true,
        ]);
    }
800377
public function addClass(DocumentMetadata $metadata): void
    {
        $this->graph->addNode($metadata->name);

        $assocNames = $metadata->getAssociationNames();
        foreach ($assocNames as $assocName) {
            $targetClass = $metadata->getAssociationTargetClass($assocName);
            $this->graph->addNode($targetClass);
            $this->graph->connect($metadata->name, $targetClass);
        }
    }
586138
protected function buildMap(array $metadata)
    {
        $className = $this->getMapClassName();
        $map = new $className($metadata['class']);

        foreach ($metadata['definitions'] as $metadataDefinition) {
            $definition = $this->buildDefinition($metadataDefinition);
            $map->addDefinition($definition);
        }

        return $map;
    }
654040
public function loadMetadataForClass($className, ClassMetadata $metadata)
    {
        foreach ($this->getJoinEntityConfigCollection() as $targetClassName => $config) {
            if ($this->getAuditObjectManager()
                ->getRepository(Entity\AuditEntity::class)
                ->generateClassName($targetClassName) == $className
            ) {
                $foundClassName = true;
                break;
            }
        }

        // @codeCoverageIgnoreStart
        if (! $foundClassName) {
            return false;
        }
        // @codeCoverageIgnoreEnd

        $metadataFactory = $this->getObjectManager()->getMetadataFactory();
        $builder = new ClassMetadataBuilder($metadata);
        $metadata = $metadataFactory->getMetadataFor($config['ownerEntity']);

        foreach ($metadata->getAssociationMappings() as $mapping) {
            if (isset($mapping['joinTable'])) {
                if ($mapping['joinTable']['name'] == $config['tableName']) {
                    $foundJoinEntity = true;
                    break;
                }
            }
        }

        // @codeCoverageIgnoreStart
        if (! $foundJoinEntity) {
            throw new Exception(
                'joinTable '
                . $targetClassName
                . ' not found by tableName '
                . $config['tableName']
                . ' on ownerEntity: '
                . $config['ownerEntity']
            );
        }
        // @codeCoverageIgnoreEnd

        $fields = [];
        foreach ($mapping['joinTable']['joinColumns'] as $column) {
            $column['dataType'] = $this->getObjectManager()
                ->getClassMetadata($mapping['sourceEntity'])
                ->getTypeOfField($column['referencedColumnName']);
            $fields[] = $column;
        }
        foreach ($mapping['joinTable']['inverseJoinColumns'] as $column) {
            $column['dataType'] = $this->getObjectManager()
                ->getClassMetadata($mapping['targetEntity'])
                ->getTypeOfField($column['referencedColumnName']);
            $fields[] = $column;
        }

        $identifiers = [];
        foreach ($fields as $field) {
            $builder->addField(
                $field['name'],
                $field['dataType'],
                [
                // 'nullable' => $config['nullable'],
                    'columnName' => $field['name'],
                    'id' => true,
                ]
            );
        }

        $association = $builder->createManyToOne('revisionEntity', Entity\RevisionEntity::class);
        $association->makePrimaryKey();
        $association->build();

        $builder->setTable(
            $this->getAuditOptions()->getAuditTableNamePrefix()
            . $config['tableName']
            . $this->getAuditOptions()->getAuditTableNameSuffix()
        );
    }
1326270
public function loadMetadataForClass($className, ClassMetadata $metadata)
    {
        $class = $metadata->getReflectionClass();

        if (!$class) {
            $class = new \ReflectionClass((string) $className);
        }

        $classAnnotations = $this->reader->getClassAnnotations($class);
        
        $classMapping = array();
        $validMapping = false;
        foreach ($classAnnotations as $annotation) {
            switch(get_class($annotation)) {
                case 'Doctrine\Search\Mapping\Annotations\ElasticSearchable':
                    $classMapping = (array) $annotation;
                    $classMapping['class'] = 'ElasticSearchable';
                    $validMapping = true;
                    break;
                case 'Doctrine\Search\Mapping\Annotations\Searchable':
                    $classMapping = (array) $annotation;
                    $classMapping['class'] = 'Searchable';
                    $validMapping = true;
                    break;
                case 'Doctrine\Search\Mapping\Annotations\ElasticRoot':
                    $rootMapping = (array) $annotation;
                    $metadata->mapRoot($this->rootToArray($rootMapping));
                    break;
            }
        }
        
        if (!$validMapping) {
            throw MappingException::classIsNotAValidDocument($className);
        }
        
        $this->annotateClassMetadata($classMapping, $metadata);

        $properties = $class->getProperties();
        foreach ($properties as $property) {
            $propertyAnnotations = $this->reader->getPropertyAnnotations($property);
            foreach ($propertyAnnotations as $annotation) {
                switch (get_class($annotation)) {
                    case 'Doctrine\Search\Mapping\Annotations\Id':
                        $metadata->identifier = $property->getName();
                        break;
                    case 'Doctrine\Search\Mapping\Annotations\Parameter':
                        $mapping = $this->parameterToArray($property->getName(), (array) $annotation);
                        $metadata->mapParameter($mapping);
                        break;
                    case 'Doctrine\Search\Mapping\Annotations\Field':
                    case 'Doctrine\Search\Mapping\Annotations\ElasticField':
                    case 'Doctrine\Search\Mapping\Annotations\SolrField':
                        $mapping = $this->fieldToArray($property->getName(), (array) $annotation);
                        $metadata->mapField($mapping);
                        break;
                }
            }
        }
    }
364305
public function addMeta(\Sulu\Bundle\MediaBundle\Entity\FileVersionMeta $meta)
    {
        $this->meta[] = $meta;

        return $this;
    }