Add mapping data to a translatable entity

@param ClassMetadata $mapping
@return void
436988
private function mapTranslatable(ClassMetadata $mapping)
    {
        $metadata = $this->getTranslatableMetadata($mapping->name);

        if ($metadata->targetEntity
            && $metadata->translations
            && !$mapping->hasAssociation($metadata->translations->name)
        ) {
            $targetMetadata = $this->getTranslatableMetadata($metadata->targetEntity);

            $mapping->mapOneToMany(array(
                'fieldName'     => $metadata->translations->name,
                'targetEntity'  => $metadata->targetEntity,
                'mappedBy'      => $targetMetadata->translatable->name,
                'fetch'         => ClassMetadataInfo::FETCH_EXTRA_LAZY,
                'indexBy'       => $targetMetadata->locale->name,
                'cascade'       => array('persist', 'merge', 'remove'),
                'orphanRemoval' => true,
            ));
        }
    }
948114
public function setLockMetadata(PropertyMetadata $mapping)
    {
        if ($mapping->type !== 'int') {
            throw LockException::invalidLockAttributeType($mapping->type);
        }

        $this->isLockable   = true;
        $this->lockMetadata = $mapping;
    }
195868
protected function _validateAndCompleteOneToOneMapping(array $mapping)
    {
        $mapping = $this->_validateAndCompleteAssociationMapping($mapping);

        if (isset($mapping['joinColumns']) && $mapping['joinColumns']) {
            $mapping['isOwningSide'] = true;
        }

        if ($mapping['isOwningSide']) {
            if ( ! isset($mapping['joinColumns']) || ! $mapping['joinColumns']) {
                // Apply default join column
                $mapping['joinColumns'] = array(array(
                    'name' => $this->namingStrategy->joinColumnName($mapping['fieldName'], $this->name),
                    'referencedColumnName' => $this->namingStrategy->referenceColumnName()
                ));
            }

            $uniqueConstraintColumns = array();
            foreach ($mapping['joinColumns'] as &$joinColumn) {
                if ($mapping['type'] === self::ONE_TO_ONE && ! $this->isInheritanceTypeSingleTable()) {
                    if (count($mapping['joinColumns']) == 1) {
                        if ( ! isset($mapping['id']) || ! $mapping['id']) {
                            $joinColumn['unique'] = true;
                        }
                    } else {
                        $uniqueConstraintColumns[] = $joinColumn['name'];
                    }
                }

                if (empty($joinColumn['name'])) {
                    $joinColumn['name'] = $this->namingStrategy->joinColumnName($mapping['fieldName'], $this->name);
                }

                if (empty($joinColumn['referencedColumnName'])) {
                    $joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName();
                }

                if ($joinColumn['name'][0] === '`') {
                    $joinColumn['name']   = trim($joinColumn['name'], '`');
                    $joinColumn['quoted'] = true;
                }

                if ($joinColumn['referencedColumnName'][0] === '`') {
                    $joinColumn['referencedColumnName'] = trim($joinColumn['referencedColumnName'], '`');
                    $joinColumn['quoted']               = true;
                }

                $mapping['sourceToTargetKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName'];
                $mapping['joinColumnFieldNames'][$joinColumn['name']] = isset($joinColumn['fieldName'])
                        ? $joinColumn['fieldName'] : $joinColumn['name'];
            }

            if ($uniqueConstraintColumns) {
                if ( ! $this->table) {
                    throw new RuntimeException("ClassMetadataInfo::setTable() has to be called before defining a one to one relationship.");
                }
                $this->table['uniqueConstraints'][$mapping['fieldName']."_uniq"] = array(
                    'columns' => $uniqueConstraintColumns
                );
            }

            $mapping['targetToSourceKeyColumns'] = array_flip($mapping['sourceToTargetKeyColumns']);
        }

        $mapping['orphanRemoval']   = isset($mapping['orphanRemoval']) ? (bool) $mapping['orphanRemoval'] : false;
        $mapping['isCascadeRemove'] = $mapping['orphanRemoval'] ? true : $mapping['isCascadeRemove'];

        if ($mapping['orphanRemoval']) {
            unset($mapping['unique']);
        }

        if (isset($mapping['id']) && $mapping['id'] === true && !$mapping['isOwningSide']) {
            throw MappingException::illegalInverseIdentifierAssociation($this->name, $mapping['fieldName']);
        }

        return $mapping;
    }
158324
protected function parseMapping(array $mapping) {
        foreach ($mapping['properties'] as $i => $property) {
            $name = $property['name'];
            $type = $property['type'];

            if (!isset($property['column'     ])) $property['column'     ] = $name;
            if (!isset($property['column-type'])) $property['column-type'] = $type;     // TODO: bug, $type may be a custom type

            if (isset($property['primary']) && $property['primary']===true)
                $mapping['identity'] = &$property;

            if (isset($property['version']) && $property['version']===true)
                $mapping['version'] = &$property;

            $column = $property['column'];
            $mapping['columns'][$column] = &$property;

            if ($type=='bool' || $type=='boolean') {
                $mapping['getters']['is'.$name ] = &$property;
                $mapping['getters']['has'.$name] = &$property;
            }
            else {
                $mapping['getters']['get'.$name] = &$property;
            }
            $mapping['properties'][$name] = &$property;
            unset($mapping['properties'][$i], $property);
        };

        if (isset($mapping['relations'])) {
            foreach ($mapping['relations'] as $i => $property) {
                $name  = $property['name' ];
                $assoc = $property['assoc'];

                // any association using a mandatory or optional join table
                if ($assoc=='many-to-many' || isset($property['join-table'])) {
                    if (!isset($property['join-table']))                       throw new RuntimeException('Missing attribute "join-table"="{table_name}" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                    if (!isset($property['key']))
                        $property['key'] = $mapping['identity']['name'];
                    else if (!isset($mapping['properties'][$property['key']])) throw new RuntimeException('Illegal attribute "key"="'.$property['key'].'" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                    if (!isset($property['ref-column']))                       throw new RuntimeException('Missing attribute "ref-column"="{'.$property['join-table'].'.column_name}" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                    if (!isset($property['fk-ref-column']))                    throw new RuntimeException('Missing attribute "fk-ref-column"="{'.$property['join-table'].'.column_name}" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                }

                // one-to-one (using no optional join table)
                else if ($assoc == 'one-to-one') {
                    if (!isset($property['column'])) {
                        if (!isset($property['key']))
                            $property['key'] = $mapping['identity']['name'];
                        else if (!isset($mapping['properties'][$property['key']])) throw new RuntimeException('Illegal attribute "key"="'.$property['key'].'" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                        if (!isset($property['ref-column']))                       throw new RuntimeException('Missing attribute "ref-column"="{column_name}" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                    }
                }

                // one-to-many (using no optional join table)
                else if ($assoc == 'one-to-many') {
                    if (!isset($property['key']))
                        $property['key'] = $mapping['identity']['name'];
                    else if (!isset($mapping['properties'][$property['key']])) throw new RuntimeException('Illegal attribute "key"="'.$property['key'].'" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                    if (!isset($property['ref-column']))                       throw new RuntimeException('Missing attribute "ref-column"="{column_name}" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                }

                // many-to-one (using no optional join table)
                else if ($assoc == 'many-to-one') {
                    if (!isset($property['column'])) throw new RuntimeException('Missing attribute "column"="{column_name}" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                }
                else                                 throw new RuntimeException('Illegal attribute "assoc"="'.$assoc.'" in relation [name="'.$name.'"...] of entity class "'.$mapping['class'].'"');

                if (isset($property['column']))
                    $mapping['columns'][$property['column']] = &$property;
                $getter = 'get'.$name;
                $mapping['getters'][$getter] = &$property;
                $mapping['relations'][$name] = &$property;
                unset($mapping['relations'][$i], $property);
            };
        }
        else $mapping['relations'] = [];

        $mapping['columns'] = \array_change_key_case($mapping['columns'], CASE_LOWER);
        $mapping['getters'] = \array_change_key_case($mapping['getters'], CASE_LOWER);

        return $mapping;
    }
116553
public function setMappings(array $mappings) {
        $this->mappings = [];

        foreach ($mappings as $contentType => $dataClass) {
            $this->addMapping($contentType, $dataClass);
        }
    }
1353850
private function addConfigFields(ClassMetadata $metadata, $className)
    {
        foreach ($metadata->getFieldNames() as $field) {
            if (!$metadata->isIdentifier($field)) {
                $this->configs[$className][0][$field] = $metadata->getTypeOfField($field);
            }
        }
    }
1065790
protected function addMapping(ActionMapping $mapping) {
        if ($this->configured) throw new IllegalStateException('Configuration is frozen');

        if ($mapping->isDefault()) {
            if ($this->defaultMapping) throw new StrutsConfigException('Only one action mapping can be marked as "default" within a module.');
            $this->defaultMapping = $mapping;
        }

        $name = $mapping->getName();
        if (strlen($name)) {
            if (isset($this->mappings['names'][$name])) throw new StrutsConfigException('All action mappings must have unique name attributes, non-unique name: "'.$name.'"');
            $this->mappings['names'][$name] = $mapping;
        }

        $path = $mapping->getPath();
        if (!strEndsWith($path, '/'))
            $path .= '/';
        if (isset($this->mappings['paths'][$path])) throw new StrutsConfigException('All action mappings must have unique path attributes, non-unique path: "'.$mapping->getPath().'"');
        $this->mappings['paths'][$path] = $mapping;
    }
1136124
public function loadMetadataForClass($className, ClassMetadata $metadata)
    {
        $this->mappers->getMapperFor($className)->map(
            $this->getFluent($metadata)
        );
    }
38183
private function mapTranslatable(ClassMetadata $metadata): void
    {
        $className = $metadata->name;

        try {
            $resourceMetadata = $this->resourceMetadataRegistry->getByClass($className);
        } catch (\InvalidArgumentException $exception) {
            return;
        }

        if (!$resourceMetadata->hasParameter('translation')) {
            return;
        }

        /** @var MetadataInterface $translationResourceMetadata */
        $translationResourceMetadata = $this->resourceMetadataRegistry->get($resourceMetadata->getAlias() . '_translation');

        if (!$metadata->hasAssociation('translations')) {
            $metadata->mapOneToMany([
                'fieldName' => 'translations',
                'targetEntity' => $translationResourceMetadata->getClass('model'),
                'mappedBy' => 'translatable',
                'fetch' => ClassMetadataInfo::FETCH_EXTRA_LAZY,
                'indexBy' => 'locale',
                'cascade' => ['persist', 'merge', 'remove'],
                'orphanRemoval' => true,
            ]);
        }
    }
441153
private function mapTranslation(ClassMetadata $metadata): void
    {
        $className = $metadata->name;

        try {
            $resourceMetadata = $this->resourceMetadataRegistry->getByClass($className);
        } catch (\InvalidArgumentException $exception) {
            return;
        }

        /** @var MetadataInterface $translatableResourceMetadata */
        $translatableResourceMetadata = $this->resourceMetadataRegistry->get(str_replace('_translation', '', $resourceMetadata->getAlias()));

        if (!$metadata->hasAssociation('translatable')) {
            $metadata->mapManyToOne([
                'fieldName' => 'translatable',
                'targetEntity' => $translatableResourceMetadata->getClass('model'),
                'inversedBy' => 'translations',
                'joinColumns' => [[
                    'name' => 'translatable_id',
                    'referencedColumnName' => 'id',
                    'onDelete' => 'CASCADE',
                    'nullable' => false,
                ]],
            ]);
        }

        if (!$metadata->hasField('locale')) {
            $metadata->mapField([
                'fieldName' => 'locale',
                'type' => 'string',
                'nullable' => false,
            ]);
        }

        // Map unique index.
        $columns = [
            $metadata->getSingleAssociationJoinColumnName('translatable'),
            'locale',
        ];

        if (!$this->hasUniqueConstraint($metadata, $columns)) {
            $constraints = $metadata->table['uniqueConstraints'] ?? [];

            $constraints[$metadata->getTableName() . '_uniq_trans'] = [
                'columns' => $columns,
            ];

            $metadata->setPrimaryTable([
                'uniqueConstraints' => $constraints,
            ]);
        }
    }
469994
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', 'detach'],
            'orphanRemoval' => true,
        ]);

        $metadata->addEntityListener('preFlush', self::class, 'onTranslatablePreFlush');
    }
604568
public function setVersionMapping(PropertyMetadata $mapping)
    {
        if ($mapping->type !== Type::INT && $mapping->type !== Type::DATE) {
            throw LockException::invalidVersionAttributeType($mapping->type);
        }

        $this->isVersioned      = true;
        $this->versionAttribute = $mapping->name;
    }
956721
public function addAttributeMapping(PropertyMetadata $mapping)
    {
        if ($this->discriminatorAttribute !== null && $this->discriminatorAttribute === $mapping->attributeName) {
            throw MappingException::discriminatorAttributeConflict($this->name, $this->discriminatorAttribute);
        }

        if ($this->isEmbeddedDocument && $mapping->isCollectionType() && $mapping->strategy === PropertyMetadata::STORAGE_STRATEGY_ATOMIC_SET) {
            throw MappingException::atomicCollectionStrategyNotAllowed($this->name, $mapping->name);
        }

        $this->propertyMetadata[$mapping->name] = $mapping;

        if ($mapping->association !== null) {
            $this->associationMetadata[$mapping->name] = $mapping;
        }

        if ($mapping->generator !== null) {
            $this->generatedProperties[$mapping->name] = $mapping;
        }
    }
1283177
protected function validateIdentifier(ClassMetadata $class) : void
    {
        if (! $class->identifier && ! $class->isMappedSuperclass && ! $class->isEmbeddedDocument && ! $class->isQueryResultDocument) {
            throw MappingException::identifierRequired($class->name);
        }
    }
991760
public function mapManyToMany(array $mapping)
    {
        $mapping['type'] = self::MANY_TO_MANY;
        $mapping = $this->_validateAndCompleteManyToManyMapping($mapping);
        $this->_storeAssociationMapping($mapping);
    }
1289365
public function addInheritedAssociationMapping(array $mapping/*, $owningClassName = null*/)
    {
        if (isset($this->associationMappings[$mapping['fieldName']])) {
            throw MappingException::duplicateAssociationMapping($this->name, $mapping['fieldName']);
        }
        $this->associationMappings[$mapping['fieldName']] = $mapping;
    }
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);
            
        }
        
    }