Returns an array of fields. Fields can be both column fields and
association fields.

@param ClassMetadataInfo $metadata

@return array $fields
500875
private function getFieldsFromMetadata(ClassMetadataInfo $metadata)
    {
        $fields = (array)$metadata->fieldNames;
//        var_dump($fields);


        // Remove the primary key field if it's not managed manually
        if (!$metadata->isIdentifierNatural()) {
            $fields = array_diff($fields, $metadata->identifier);
        }

//        foreach ($metadata->associationMappings as $fieldName => $relation) {
//            if ($relation['type'] !== ClassMetadataInfo::ONE_TO_MANY) {
//                $fields[$fieldName] = $fieldName;
//            }
//        }
//        dump($fields);
//        exit;
//
//        dump($metadata);


        foreach ($fields as $field) {
            if (array_key_exists($field, $metadata->fieldMappings)) {
                $fields[$field] = $this->map[$metadata->fieldMappings[$field]['type']];
            }

        }
//        dump($fields);
//        exit;
        return $fields;
    }
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);
            
        }
        
    }
457759
private function getClassDiscriminatorValues(ClassMetadata $metadata)
    {
        $discriminatorValues = array($metadata->discriminatorValue);
        foreach ($metadata->subClasses as $className) {
            if ($key = array_search($className, $metadata->discriminatorMap)) {
                $discriminatorValues[] = $key;
            }
        }
        return $discriminatorValues;
    }
1287294
private function convertIndexes($className, array $model, ClassMetadataInfo $metadata)
    {
        if (empty($model['indexes'])) {
            return;
        }

        foreach ($model['indexes'] as $name => $index) {
            $type = (isset($index['type']) && $index['type'] == 'unique')
                ? 'uniqueConstraints' : 'indexes';

            $metadata->table[$type][$name] = array(
                'columns' => $index['fields']
            );
        }
    }
1200200
private function hasDateTimeField(ClassMetadata $metadata)
    {
        /* @var \Doctrine\ORM\Mapping\ClassMetadataInfo|\Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo $metadata */
        $hasDateTime = false;

        foreach ($this->getFieldsFromMetadata($metadata) as $field) {
            if (array_key_exists($field, $metadata->fieldMappings)) {
                if (in_array($metadata->fieldMappings[$field]['type'], array('date', 'time', 'datetime'))) {
                    $hasDateTime = true;

                    break;
                }
            } else {
                if (in_array($metadata->associationMappings[$field]['type'], array('date', 'time', 'datetime'))) {
                    $hasDateTime = true;

                    break;
                }
            }
        }

        return $hasDateTime;
    }
1120230
public static function getTypeOfField($fieldName, ClassMetadata $class, EntityManagerInterface $em)
    {
        if (isset($class->fieldMappings[$fieldName])) {
            return array($class->fieldMappings[$fieldName]['type']);
        }

        if ( ! isset($class->associationMappings[$fieldName])) {
            return array();
        }

        $assoc = $class->associationMappings[$fieldName];

        if (! $assoc['isOwningSide']) {
            return self::getTypeOfField($assoc['mappedBy'], $em->getClassMetadata($assoc['targetEntity']), $em);
        }

        if ($assoc['type'] & ClassMetadata::MANY_TO_MANY) {
            $joinData = $assoc['joinTable'];
        } else {
            $joinData = $assoc;
        }

        $types       = array();
        $targetClass = $em->getClassMetadata($assoc['targetEntity']);

        foreach ($joinData['joinColumns'] as $joinColumn) {
            $types[] = self::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $em);
        }

        return $types;
    }
459663
private function buildToOneAssociationMappings(ClassMetadataInfo $metadata)
    {
        $tableName   = $metadata->table['name'];
        $primaryKeys = $this->getTablePrimaryKeys($this->tables[$tableName]);
        $foreignKeys = $this->getTableForeignKeys($this->tables[$tableName]);

        foreach ($foreignKeys as $foreignKey) {
            $foreignTableName   = $foreignKey->getForeignTableName();
            $fkColumns          = $foreignKey->getColumns();
            $fkForeignColumns   = $foreignKey->getForeignColumns();
            $localColumn        = current($fkColumns);
            $associationMapping = array(
                'fieldName'    => $this->getFieldNameForColumn($tableName, $localColumn, true),
                'targetEntity' => $this->getClassNameForTable($foreignTableName),
            );

            if (isset($metadata->fieldMappings[$associationMapping['fieldName']])) {
                $associationMapping['fieldName'] .= '2'; // "foo" => "foo2"
            }

            if ($primaryKeys && in_array($localColumn, $primaryKeys)) {
                $associationMapping['id'] = true;
            }

            for ($i = 0; $i < count($fkColumns); $i++) {
                $associationMapping['joinColumns'][] = array(
                    'name'                 => $fkColumns[$i],
                    'referencedColumnName' => $fkForeignColumns[$i],
                );
            }

            // Here we need to check if $fkColumns are the same as $primaryKeys
            if ( ! array_diff($fkColumns, $primaryKeys)) {
                $metadata->mapOneToOne($associationMapping);
            } else {
                $metadata->mapManyToOne($associationMapping);
            }
        }
    }
389795
protected function generateEntityEmbeddedProperties(ClassMetadataInfo $metadata)
    {
        $lines = array();

        foreach ($metadata->embeddedClasses as $fieldName => $embeddedClass) {
            if (isset($embeddedClass['declaredField']) || $this->hasProperty($fieldName, $metadata)) {
                continue;
            }

            $lines[] = $this->generateEmbeddedPropertyDocBlock($embeddedClass);
            $lines[] = $this->spaces . $this->fieldVisibility . ' $' . $fieldName . ";\n";
        }

        return implode("\n", $lines);
    }
494229
private function loadDiscriminatorColumns(ClassMetadataInfo $metadata)
    {
        if (!\array_key_exists($metadata->name, $this->discriminatorColumns)) {
            return;
        }

        try {
            if (isset($this->discriminatorColumns[$metadata->name])) {
                $arrayDiscriminatorColumns = $this->discriminatorColumns[$metadata->name];
                if (isset($metadata->discriminatorColumn)) {
                    $arrayDiscriminatorColumns = array_merge($metadata->discriminatorColumn, $this->discriminatorColumns[$metadata->name]);
                }
                $metadata->setDiscriminatorColumn($arrayDiscriminatorColumns);
            }
        } catch (\ReflectionException $e) {
            throw new \RuntimeException(sprintf('Error with class %s : %s', $metadata->name, $e->getMessage()), 404, $e);
        }
    }
347343
private function buildToOneAssociationMappings(Mapping\ClassMetadata $metadata)
    {
        $tableName   = $metadata->getTableName();
        $primaryKeys = $this->getTablePrimaryKeys($this->tables[$tableName]);
        $foreignKeys = $this->getTableForeignKeys($this->tables[$tableName]);

        foreach ($foreignKeys as $foreignKey) {
            $foreignTableName   = $foreignKey->getForeignTableName();
            $fkColumns          = $foreignKey->getColumns();
            $fkForeignColumns   = $foreignKey->getForeignColumns();
            $localColumn        = current($fkColumns);
            $associationMapping = [
                'fieldName'    => $this->getFieldNameForColumn($tableName, $localColumn, true),
                'targetEntity' => $this->getClassNameForTable($foreignTableName),
            ];

            if ($metadata->getProperty($associationMapping['fieldName'])) {
                $associationMapping['fieldName'] .= '2'; // "foo" => "foo2"
            }

            if ($primaryKeys && in_array($localColumn, $primaryKeys, true)) {
                $associationMapping['id'] = true;
            }

            for ($i = 0, $l = count($fkColumns); $i < $l; $i++) {
                $joinColumn = new Mapping\JoinColumnMetadata();

                $joinColumn->setColumnName($fkColumns[$i]);
                $joinColumn->setReferencedColumnName($fkForeignColumns[$i]);

                $associationMapping['joinColumns'][] = $joinColumn;
            }

            // Here we need to check if $fkColumns are the same as $primaryKeys
            if (! array_diff($fkColumns, $primaryKeys)) {
                $metadata->addProperty($associationMapping);
            } else {
                $metadata->addProperty($associationMapping);
            }
        }
    }
142654
public function getMetadata(): array
    {
        if ($this->metadata === null) {
            $this->metadata = $this->readMetadata();

            ksort($this->metadata);
        }

        return $this->metadata;
    }
705514
public function getFieldsNames(): array
    {
        $fields         = static::db()->metadata()->getColumnsMetadata(static::getTableName())['fields'];
        $classVars      = array_keys(get_class_vars(get_class($this)));
        $selectedFields = array_intersect($classVars, $fields);

        return $selectedFields;
    }
289279
protected function generateEntityBody(ClassMetadataInfo $metadata)
    {
        $fieldMappingProperties = $this->generateEntityFieldMappingProperties($metadata);
        $embeddedProperties = $this->generateEntityEmbeddedProperties($metadata);
        $associationMappingProperties = $this->generateEntityAssociationMappingProperties($metadata);
        $stubMethods = $this->generateEntityStubMethods ? $this->generateEntityStubMethods($metadata) : null;
        $lifecycleCallbackMethods = $this->generateEntityLifecycleCallbackMethods($metadata);

        $code = array();

        if ($fieldMappingProperties) {
            $code[] = $fieldMappingProperties;
        }

        if ($embeddedProperties) {
            $code[] = $embeddedProperties;
        }

        if ($associationMappingProperties) {
            $code[] = $associationMappingProperties;
        }

        $code[] = $this->generateEntityConstructor($metadata);

        if ($stubMethods) {
            $code[] = $stubMethods;
        }

        if ($lifecycleCallbackMethods) {
            $code[] = $lifecycleCallbackMethods;
        }

        return implode("\n", $code);
    }
808863
public static function loadValidatorMetadata(ClassMetadata $metadata)
    {
        $metadata->addPropertyConstraint('companyName', new Assert\Type(array('type' => 'string')));
        $metadata->addPropertyConstraint('companyName', new Assert\Length(array('max' => 35)));

        $metadata->addPropertyConstraint('civility', new Assert\Type(array('type' => 'string')));
        $metadata->addPropertyConstraint('civility', new Assert\Length(array('max' => 4)));

        $metadata->addPropertyConstraint('name', new Assert\Type(array('type' => 'string')));
        $metadata->addPropertyConstraint('name', new Assert\Length(array('max' => 35)));

        $metadata->addPropertyConstraint('surname', new Assert\Type(array('type' => 'string')));
        $metadata->addPropertyConstraint('surname', new Assert\Length(array('max' => 29)));

        $metadata->addPropertyConstraint('email', new Assert\Type(array('type' => 'string')));
        $metadata->addPropertyConstraint('email', new Assert\Email());

        $metadata->addPropertyConstraint('line0', new Assert\Type(array('type' => 'string')));
        $metadata->addPropertyConstraint('line0', new Assert\Length(array('max' => 35)));

        $metadata->addPropertyConstraint('line1', new Assert\Type(array('type' => 'string')));
        $metadata->addPropertyConstraint('line1', new Assert\Length(array('max' => 35)));

        $metadata->addPropertyConstraint('line2', new Assert\Type(array('type' => 'string')));
        $metadata->addPropertyConstraint('line2', new Assert\NotBlank());
        $metadata->addPropertyConstraint('line2', new Assert\Length(array('max' => 35)));

        $metadata->addPropertyConstraint('line3', new Assert\Type(array('type' => 'string')));
        $metadata->addPropertyConstraint('line3', new Assert\Length(array('max' => 35)));

        $metadata->addPropertyConstraint('phone', new Assert\Regex(array('pattern' => '/^[0-9]{0,15}$/')));
        $metadata->addPropertyConstraint('mobileNumber', new Assert\Regex(array('pattern' => '/^[0-9]{0,10}$/')));
        $metadata->addPropertyConstraint('doorCode1', new Assert\Regex(array('pattern' => '/^[a-zA-Z0-9]{0,8}$/')));
        $metadata->addPropertyConstraint('doorCode2', new Assert\Regex(array('pattern' => '/^[a-zA-Z0-9]{0,8}$/')));
        $metadata->addPropertyConstraint('interphone', new Assert\Regex(array('pattern' => '/^[a-zA-Z0-9]{0,30}$/')));

        $metadata->addPropertyConstraint('countryCode', new Assert\NotBlank());
        $metadata->addPropertyConstraint('countryCode', new Assert\Regex(array('pattern' => '/^[A-Z]{2}$/')));

        $metadata->addPropertyConstraint('city', new Assert\Type(array('type' => 'string')));
        $metadata->addPropertyConstraint('city', new Assert\NotBlank());
        $metadata->addPropertyConstraint('city', new Assert\Length(array('max' => 35)));

        $metadata->addPropertyConstraint('postalCode', new Assert\NotBlank());
        $metadata->addPropertyConstraint('postalCode', new Assert\Regex(array('pattern' => '/^[a-zA-Z0-9]{5}$/')));
    }
777281
private function hydrateDataObject(ClassMetadata $metadata, array $parentName = array())
    {
        $dataObject = new MetadataDataObjectDoctrine2(
            new MetaDataColumnCollection(),
            new MetaDataRelationCollection()
        );

        $columnDataObject = new MetaDataColumn();

        foreach ($metadata->fieldMappings as $field => $columnMetadata) {
            $column = clone $columnDataObject;
            $column->setName($field)
                   ->setType($columnMetadata['type'])
                   ->setLength(isset($columnMetadata['length']) === true ? $columnMetadata['length'] : null)
                   ->setNullable($columnMetadata['nullable'])
                   ->setPrimaryKey((in_array($field, $metadata->identifier) === true ? true : false));

            $dataObject->appendColumn($column);
        }

        $dataObject = $this->hydrateAssociation($metadata, $dataObject, $parentName);

        $dataObject->setName($metadata->name);

        return $dataObject;
    }
1321773
public function merge(array $metadata): array
	{
		$tables = [];
		foreach ($metadata as $entity) {
			$tables[$entity->getTableName()][] = $entity;
		}

		$merged = [];
		foreach ($tables as $table => $metadata) {

			if (count($metadata) === 1) {
				$merged[] = array_shift($metadata);
				continue;
			}

			$primary = $this->resolvePrimaryMetadata($metadata);
			foreach ($metadata as $secondary) {
				$primary = $this->mergeMetadata($primary, $secondary);
			}

			$primary->fieldMappings = $this->mappingCleanup($primary->fieldMappings);
			$primary->associationMappings = $this->mappingCleanup($primary->associationMappings);
			$merged[] = $primary;
		}

		return $merged;
	}
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;
                }
            }
        }
    }