Generates and writes entity classes for the given array of ClassMetadataInfo instances.

@param array  $metadatas
@param string $outputDirectory

@return void
329136
public function generate(array $metadatas, $outputDirectory)
    {
        foreach ($metadatas as $metadata) {
            $this->writeEntityClass($metadata, $outputDirectory);
        }
    }
405647
public function generateUpdatedXmlEntityClass(ClassMetadataInfo $metadata, $path)
    {
        $currentCode = file_get_contents($path);

        $body = $this->generateXmlEntityBody($metadata);
        $body = str_replace('<spaces>', $this->spaces, $body);
        $last = strrpos($currentCode, '}');

        return substr($currentCode, 0, $last) . $body . (strlen($body) > 0 ? "\n" : ''). "}";
    }
406146
private function executeInserts(ClassMetadata $class) : void
    {
        $className      = $class->getClassName();
        $persister      = $this->getEntityPersister($className);
        $invoke         = $this->listenersInvoker->getSubscribedSystems($class, Events::postPersist);
        $generationPlan = $class->getValueGenerationPlan();

        foreach ($this->entityInsertions as $oid => $entity) {
            if ($this->em->getClassMetadata(get_class($entity))->getClassName() !== $className) {
                continue;
            }

            $persister->insert($entity);

            if ($generationPlan->containsDeferred()) {
                // Entity has post-insert IDs
                $oid = spl_object_id($entity);
                $id  = $persister->getIdentifier($entity);

                $this->entityIdentifiers[$oid]  = $this->em->getIdentifierFlattener()->flattenIdentifier($class, $id);
                $this->entityStates[$oid]       = self::STATE_MANAGED;
                $this->originalEntityData[$oid] = $id + $this->originalEntityData[$oid];

                $this->addToIdentityMap($entity);
            }

            unset($this->entityInsertions[$oid]);

            if ($invoke !== ListenersInvoker::INVOKE_NONE) {
                $eventArgs = new LifecycleEventArgs($entity, $this->em);

                $this->listenersInvoker->invoke($class, Events::postPersist, $entity, $eventArgs, $invoke);
            }
        }
    }
1023900
public function BuildClassBody($tableColumnsMetadata) {
        $this->AddConstants($tableColumnsMetadata);
        $this->AddFields($tableColumnsMetadata);
        $this->AddSetters($tableColumnsMetadata);
        $this->AddGetters($tableColumnsMetadata);
    }
334844
protected function _saveMetadatas($id, $metadatas)
    {
        $file = $this->_metadatasFile($id);
        $result = $this->_filePutContents($file, serialize($metadatas));
        if (!$result) {
            return false;
        }
        return true;
    }
229727
private function toIdentifierArray(ClassMetadata $metadata, $identifier)
    {
        if (is_object($identifier) && $this->em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($identifier))) {
            $identifier = $this->uow->getSingleIdentifierValue($identifier);

            if ($identifier === null) {
                throw ORMInvalidArgumentException::invalidIdentifierBindingEntity();
            }
        }

        return array($metadata->identifier[0] => $identifier);
    }
130152
private function generateEmbeddableConstructor(ClassMetadataInfo $metadata)
    {
        $paramTypes = array();
        $paramVariables = array();
        $params = array();
        $fields = array();

        // Resort fields to put optional fields at the end of the method signature.
        $requiredFields = array();
        $optionalFields = array();

        foreach ($metadata->fieldMappings as $fieldMapping) {
            if (empty($fieldMapping['nullable'])) {
                $requiredFields[] = $fieldMapping;

                continue;
            }

            $optionalFields[] = $fieldMapping;
        }

        $fieldMappings = array_merge($requiredFields, $optionalFields);

        foreach ($metadata->embeddedClasses as $fieldName => $embeddedClass) {
            $paramType = '\\' . ltrim($embeddedClass['class'], '\\');
            $paramVariable = '$' . $fieldName;

            $paramTypes[] = $paramType;
            $paramVariables[] = $paramVariable;
            $params[] = $paramType . ' ' . $paramVariable;
            $fields[] = '$this->' . $fieldName . ' = ' . $paramVariable . ';';
        }

        foreach ($fieldMappings as $fieldMapping) {
            if (isset($fieldMapping['declaredField']) &&
                isset($metadata->embeddedClasses[$fieldMapping['declaredField']])
            ) {
                continue;
            }

            $paramTypes[] = $this->getType($fieldMapping['type']) . (!empty($fieldMapping['nullable']) ? '|null' : '');
            $param = '$' . $fieldMapping['fieldName'];
            $paramVariables[] = $param;

            if ($fieldMapping['type'] === 'datetime') {
                $param = $this->getType($fieldMapping['type']) . ' ' . $param;
            }

            if (!empty($fieldMapping['nullable'])) {
                $param .= ' = null';
            }

            $params[] = $param;

            $fields[] = '$this->' . $fieldMapping['fieldName'] . ' = $' . $fieldMapping['fieldName'] . ';';
        }

        $maxParamTypeLength = max(array_map('strlen', $paramTypes));
        $paramTags = array_map(
            function ($type, $variable) use ($maxParamTypeLength) {
                return '@param ' . $type . str_repeat(' ', $maxParamTypeLength - strlen($type) + 1) . $variable;
            },
            $paramTypes,
            $paramVariables
        );

        // Generate multi line constructor if the signature exceeds 120 characters.
        if (array_sum(array_map('strlen', $params)) + count($params) * 2 + 29 > 120) {
            $delimiter = "\n" . $this->spaces;
            $params = $delimiter . implode(',' . $delimiter, $params) . "\n";
        } else {
            $params = implode(', ', $params);
        }

        $replacements = array(
            '<paramTags>' => implode("\n * ", $paramTags),
            '<params>'    => $params,
            '<fields>'    => implode("\n" . $this->spaces, $fields),
        );

        $constructor = str_replace(
            array_keys($replacements),
            array_values($replacements),
            static::$embeddableConstructorMethodTemplate
        );

        return $this->prefixCodeWithSpaces($constructor);
    }
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,
            ]);
        }
    }
458871
private function buildIndexes(ClassMetadataInfo $metadata)
    {
        $tableName = $metadata->table['name'];
        $indexes   = $this->tables[$tableName]->getIndexes();

        foreach($indexes as $index){
            if ($index->isPrimary()) {
                continue;
            }

            $indexName      = $index->getName();
            $indexColumns   = $index->getColumns();
            $constraintType = $index->isUnique()
                ? 'uniqueConstraints'
                : 'indexes';

            $metadata->table[$constraintType][$indexName]['columns'] = $indexColumns;
        }
    }
614744
protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, ClassMetadataInfo $metadata)
    {
        $lines = array();
        $lines[] = $this->spaces . '/**';
        $lines[] = $this->spaces . ' * @var ' . $this->getType($fieldMapping['type']);

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

            $column = array();
            if (isset($fieldMapping['columnName'])) {
                $column[] = 'name="' . $fieldMapping['columnName'] . '"';
            }

            if (isset($fieldMapping['type'])) {
                $column[] = 'type="' . $fieldMapping['type'] . '"';
            }

            if (isset($fieldMapping['length'])) {
                $column[] = 'length=' . $fieldMapping['length'];
            }

            if (isset($fieldMapping['precision'])) {
                $column[] = 'precision=' .  $fieldMapping['precision'];
            }

            if (isset($fieldMapping['scale'])) {
                $column[] = 'scale=' . $fieldMapping['scale'];
            }

            if (isset($fieldMapping['nullable'])) {
                $column[] = 'nullable=' .  var_export($fieldMapping['nullable'], true);
            }

            if (isset($fieldMapping['unsigned']) && $fieldMapping['unsigned']) {
                $column[] = 'options={"unsigned"=true}';
            }

            if (isset($fieldMapping['columnDefinition'])) {
                $column[] = 'columnDefinition="' . $fieldMapping['columnDefinition'] . '"';
            }

            if (isset($fieldMapping['unique'])) {
                $column[] = 'unique=' . var_export($fieldMapping['unique'], true);
            }

            $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . 'Column(' . implode(', ', $column) . ')';

            if (isset($fieldMapping['id']) && $fieldMapping['id']) {
                $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . 'Id';

                if ($generatorType = $this->getIdGeneratorTypeString($metadata->generatorType)) {
                    $lines[] = $this->spaces.' * @' . $this->annotationsPrefix . 'GeneratedValue(strategy="' . $generatorType . '")';
                }

                if ($metadata->sequenceGeneratorDefinition) {
                    $sequenceGenerator = array();

                    if (isset($metadata->sequenceGeneratorDefinition['sequenceName'])) {
                        $sequenceGenerator[] = 'sequenceName="' . $metadata->sequenceGeneratorDefinition['sequenceName'] . '"';
                    }

                    if (isset($metadata->sequenceGeneratorDefinition['allocationSize'])) {
                        $sequenceGenerator[] = 'allocationSize=' . $metadata->sequenceGeneratorDefinition['allocationSize'];
                    }

                    if (isset($metadata->sequenceGeneratorDefinition['initialValue'])) {
                        $sequenceGenerator[] = 'initialValue=' . $metadata->sequenceGeneratorDefinition['initialValue'];
                    }

                    $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . 'SequenceGenerator(' . implode(', ', $sequenceGenerator) . ')';
                }
            }

            if (isset($fieldMapping['version']) && $fieldMapping['version']) {
                $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . 'Version';
            }
        }

        $lines[] = $this->spaces . ' */';

        return implode("\n", $lines);
    }
129397
protected function generateMorphableClasses(array &$metadata)
    {
        foreach ($metadata as $key => $entityMetadata) {
            foreach ($entityMetadata['relations'] as $relationKey => $relationMetadata) {
                // get morphable classes for morphTo relations
                if ($relationMetadata['type'] == 'morphTo') {
                    $metadata[$key]['relations'][$relationKey]['options']['morphableClasses']
                        = $this->getMorphableClasses($entityMetadata['class'], $relationMetadata['options']['morphName'], $metadata);
                }

                // get morphable classes for morphToMany relations
                if ($relationMetadata['type'] == 'morphToMany' && ! $relationMetadata['options']['inverse']) {
                    $metadata[$key]['relations'][$relationKey]['options']['morphableClasses']
                        = $this->getMorphableClasses($entityMetadata['class'], $relationMetadata['options']['morphName'], $metadata, true);
                }
            }
        }
    }
1304078
public function createAllGeneratorTables()
    {
        $tables = [];

        /**
         * @var ClassMetadata $class
         */
        foreach ($this->metadataFactory->getAllMetadata() as $class) {
            $tables = array_merge(
                $tables,
                $this->getGeneratorTablesFor($class)
            );
        }

        foreach ($tables as $tableName => $definition) {
            $this->doCreateTable($tableName, $definition);
        }
    }
472812
protected function writeFile(EntityMetadata $metadata, $contents)
    {
        $file = $this->getCacheFile($metadata->type);
        $tmpFile = tempnam($this->dir, 'metadata-cache');
        file_put_contents($tmpFile, $contents);
        chmod($tmpFile, 0666 & ~umask());
        $this->renameFile($tmpFile, $file);
    }
1260978
public void markMetaDataColumns(ArrayList<String> metaDataColumns) {
		for (String column : metaDataColumns) {
			metaDataColumnsHashMap.put(column, column);
		}
	}
833518
public function set_metadatas(array $metadatas, $force_readonly = false)
    {
        $databox_descriptionStructure = $this->getDatabox()->get_meta_structure();

        foreach ($metadatas as $param) {
            if (!is_array($param)) {
                throw new Exception_InvalidArgument('Invalid metadatas argument');
            }

            $db_field = $databox_descriptionStructure->get_element($param['meta_struct_id']);

            if ($db_field->is_readonly() === true && !$force_readonly) {
                continue;
            }

            $this->set_metadata($param, $this->getDatabox());
        }

        $xml = new DOMDocument();
        $xml->loadXML($this->app['serializer.caption']->serialize($this->get_caption(), CaptionSerializer::SERIALIZE_XML, true));

        $this->set_xml($xml);
        unset($xml);

        $this->write_metas();
        $this->dispatch(RecordEvents::METADATA_CHANGED, new MetadataChangedEvent($this));

        return $this;
    }
650912
private function generateMethods(): void
    {
        $this->printer->writeln('Generating methods.');
        $this->generator->setChildNamespace('Method');

        /** @var Method $method */
        foreach ($this->wsdl->getMethods() as $name => $method) {
            $this->printer->writeln(" |\-Generating method $name");
            $code = $method->visit($this->generator);
            $className = $this->findClassName($code);
            $filename = $this->destination . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php';

            $this->writer->writeFile($filename, $code);
            $this->printer->writeln("  |- Wrote $className to $filename");
        }
    }
780799
private function validateDatabase(EntityMetadata $metadata)
    {
        $persistence = $metadata->persistence;
        if (false === $metadata->isChildEntity() && (empty($persistence->db) || empty($persistence->collection))) {
            throw MetadataException::invalidMetadata($metadata->type, 'The persistence database and collection names cannot be empty.');
        }
    }