@param ClassMetadataInfo $metadata

@return string
962435
protected function generateEntityAssociationMappingProperties(ClassMetadataInfo $metadata)
    {
        $lines = array();

        foreach ($metadata->associationMappings as $associationMapping) {
            if ($this->hasProperty($associationMapping['fieldName'], $metadata)) {
                continue;
            }

            $lines[] = $this->generateAssociationMappingPropertyDocBlock($associationMapping, $metadata);
            $lines[] = $this->spaces . $this->fieldVisibility . ' $' . $associationMapping['fieldName']
                     . ($associationMapping['type'] == 'manyToMany' ? ' = array()' : null) . ";\n";
        }

        return implode("\n", $lines);
    }
578165
public function metadata($metadata = null) {
        if ($metadata === null) {
            return $this->metadata;
        }

        $this->metadata = (bool) $metadata;

        return $this;
    }
630457
protected function getTraits(ClassMetadataInfo $metadata)
    {
        if (! ($metadata->reflClass !== null || class_exists($metadata->name))) {
            return [];
        }

        $reflClass = $metadata->reflClass === null
            ? new \ReflectionClass($metadata->name)
            : $metadata->reflClass;

        $traits = array();

        while ($reflClass !== false) {
            $traits = array_merge($traits, $reflClass->getTraits());

            $reflClass = $reflClass->getParentClass();
        }

        return $traits;
    }
398624
protected function onMetaReceived($metaData)
    {
        $keys = array_keys($metaData["columns"]);
        $values = array_values($metaData["columns"]);

        for ($i = 0; $i < count($keys); $i++) {
            if (isset($this->params[$keys[$i]])) {
                $keys[$i] = $this->params[$keys[$i]];
            }
        }
        $metaData["columns"] = array_combine($keys, $values);
        return $metaData;
    }
459859
public function getFieldsFromMetadata(ClassMetadata $metadata)
    {
        /* @var \Doctrine\ORM\Mapping\ClassMetadataInfo|\Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo $metadata */
        $fields = (array) $metadata->getFieldNames();

        $exclude = array(
            'createdAt', 'created_at', 'createdBy', 'created_by',
            'updatedAt', 'updated_at', 'updatedBy', 'updated_by',
        );

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

        foreach ($metadata->associationMappings as $fieldName => $relation) {
            if ($relation['type'] !== 4) {
                $fields[] = $fieldName;
            }
        }

        return array_values(array_diff($fields, $exclude));
    }
420183
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->mappings[$metadata->name])) {
            return;
        }

        $config = $this->mappings[$metadata->name];
        $mapping = $config['translation']['mapping'];

        $metadata->mapManyEmbedded([
            'fieldName' => $mapping['translatable']['translations'],
            'targetDocument' => $config['translation']['model'],
            'strategy' => 'set',
        ]);
    }
628308
private function getFieldsDataFromMetadata(ClassMetadataInfo $metadata)
    {
        $fieldsData = (array) $metadata->fieldMappings;

        // Convert type to filter widget
        foreach ($fieldsData as $fieldName => $data) {
            $fieldsData[$fieldName]['fieldName'] = $fieldName;
            $fieldsData[$fieldName]['filterWidget'] = $this->getFilterType($fieldsData[$fieldName]['type'], $fieldName);
        }

        return $fieldsData;
    }
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,
        ]);
    }
884616
private function getFieldsWithFilterTypeFromMetadata(ClassMetadata $metadata)
    {
        $mapping = array(
            'string' => 'ORM\StringFilterType',
            'text' => 'ORM\StringFilterType',
            'integer' => 'ORM\NumberFilterType',
            'smallint' => 'ORM\NumberFilterType',
            'bigint' => 'ORM\NumberFilterType',
            'decimal' => 'ORM\NumberFilterType',
            'boolean' => 'ORM\BooleanFilterType',
            'date' => 'ORM\DateFilterType',
            'datetime' => 'ORM\DateFilterType',
            'time' => 'ORM\DateFilterType',
        );

        $fields = array();

        foreach ($this->getFieldsFromMetadata($metadata) as $fieldName) {
            $type = $metadata->getTypeOfField($fieldName);
            $filterType = isset($mapping[$type]) ? $mapping[$type] : null;

            preg_match_all('/((?:^|[A-Z])[a-z]+)/', $fieldName, $matches);
            $fieldTitle = ucfirst(strtolower(implode(' ', $matches[0])));

            if (!is_null($filterType)) {
                $fields[$fieldName] = array('filterType' => $filterType, 'fieldTitle' => $fieldTitle);
            }
        }

        return $fields;
    }
1313637
private function getClassName(array $metadata)
    {
        return ($pos = strrpos($metadata['name'], '\\'))
            ? substr($metadata['name'], $pos + 1, strlen($metadata['name'])) : $metadata['name'];
    }
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);
    }
1238159
public function transform(StreamMetaData $metadata): string
    {
        $originalUri      = $metadata->uri;
        $processingResult = self::RESULT_ABSTAIN;
        $cacheUri         = $this->cacheManager->getCachePathForResource($originalUri);
        // Guard to disable overwriting of original files
        if ($cacheUri === $originalUri) {
            return self::RESULT_ABORTED;
        }

        $lastModified  = filemtime($originalUri);
        $cacheState    = $this->cacheManager->queryCacheState($originalUri);
        $cacheModified = $cacheState ? $cacheState['filemtime'] : 0;

        if ($cacheModified < $lastModified
            || (isset($cacheState['cacheUri']) && $cacheState['cacheUri'] !== $cacheUri)
            || !$this->container->isFresh($cacheModified)
        ) {
            $processingResult = $this->processTransformers($metadata);
            if ($processingResult === self::RESULT_TRANSFORMED) {
                $parentCacheDir = dirname($cacheUri);
                if (!is_dir($parentCacheDir)) {
                    mkdir($parentCacheDir, $this->cacheFileMode, true);
                }
                file_put_contents($cacheUri, $metadata->source, LOCK_EX);
                // For cache files we don't want executable bits by default
                chmod($cacheUri, $this->cacheFileMode & (~0111));
            }
            $this->cacheManager->setCacheState($originalUri, [
                'filemtime' => $_SERVER['REQUEST_TIME'] ?? time(),
                'cacheUri'  => ($processingResult === self::RESULT_TRANSFORMED) ? $cacheUri : null
            ]);

            return $processingResult;
        }

        if ($cacheState) {
            $processingResult = isset($cacheState['cacheUri']) ? self::RESULT_TRANSFORMED : self::RESULT_ABORTED;
        }
        if ($processingResult === self::RESULT_TRANSFORMED) {
            // Just replace all tokens in the stream
            $metadata->tokenStream = token_get_all(file_get_contents($cacheUri));
        }

        return $processingResult;
    }
545523
public function generateDocumentClass(array $metadata)
    {
        return implode(
            "\n",
            [
                "<?php\n",
                sprintf('namespace %s;', substr($metadata['name'], 0, strrpos($metadata['name'], '\\'))) . "\n",
                $this->generateDocumentUse($metadata),
                $this->generateDocumentDocBlock($metadata),
                'class ' . $this->getClassName($metadata),
                "{",
                str_replace('<spaces>', $this->spaces, $this->generateDocumentBody($metadata)),
                "}\n"
            ]
        );
    }
296188
private function convertTableName($className, array $model, ClassMetadataInfo $metadata)
    {
        if (isset($model['tableName']) && $model['tableName']) {
            $e = explode('.', $model['tableName']);

            if (count($e) > 1) {
                $metadata->table['schema'] = $e[0];
                $metadata->table['name'] = $e[1];
            } else {
                $metadata->table['name'] = $e[0];
            }
        }
    }
552018
protected function getFieldsFromMetadata($metadata)
    {
        $fields = $metadata->fieldMappings;

        // Remove the primary key field if it's not managed manually
        if (!$metadata->isIdentifierNatural()) {
            foreach ($metadata->identifier as $oneId) {
                unset($fields[$oneId]);
            }
        }

        foreach ($metadata->associationMappings as $fieldName => $relation) {
            if (in_array($relation['type'], [ClassMetadataInfo::MANY_TO_ONE, ClassMetadataInfo::ONE_TO_MANY])) {
                $fields[$fieldName] = $relation;
            } elseif ($relation['type'] == ClassMetadataInfo::MANY_TO_MANY && (empty($relation['mappedBy']) == false  || empty($relation['inversedBy'])  == false)) {
                /*|| $relation['targetEntity'] == $relation['sourceEntity']*/
                $fields[$fieldName] = $relation;
            }
        }

        return $fields;
    }
98882
public function loadMetadataForClass(
        string $className,
        Mapping\ClassMetadata $metadata,
        Mapping\ClassMetadataBuildingContext $metadataBuildingContext
    ) {
        // IMPORTANT: We're handling $metadata as "parent" metadata here, while building the $className ClassMetadata.
        $reflectionClass = new ReflectionClass($className);

        // Evaluate annotations on class metadata
        $classAnnotations = $this->getClassAnnotations($reflectionClass);
        $classMetadata    = $this->convertClassAnnotationsToClassMetadata(
            $classAnnotations,
            $reflectionClass,
            $metadata
        );

        // Evaluate @Cache annotation
        if (isset($classAnnotations[Annotation\Cache::class])) {
            $cacheAnnot = $classAnnotations[Annotation\Cache::class];
            $cache      = $this->convertCacheAnnotationToCacheMetadata($cacheAnnot, $classMetadata);

            $classMetadata->setCache($cache);
        }

        // Evaluate annotations on properties/fields
        /** @var ReflectionProperty $reflectionProperty */
        foreach ($reflectionClass->getProperties() as $reflectionProperty) {
            if ($reflectionProperty->getDeclaringClass()->getClassName() !== $reflectionClass->getName()) {
                continue;
            }

            $propertyAnnotations = $this->getPropertyAnnotations($reflectionProperty);
            $property            = $this->convertReflectionPropertyAnnotationsToProperty(
                $reflectionProperty,
                $propertyAnnotations,
                $classMetadata
            );

            $classMetadata->addDeclaredProperty($property);
        }

        return $classMetadata;
    }
64763
private function getProperties(ClassMetadata $metadata)
    {
        return array_merge(
            $metadata->getFieldNames(),
            array_map(function (array $mapping) {
                return $mapping['fieldName'];
            }, $metadata->getEmbeddedFieldsMappings())
        );
    }