Generates document constructor

@param array $metadata

@return string
511804
private function generateDocumentConstructor(array $metadata)
    {
        $fields = [];

        foreach ($metadata['properties'] as $prop) {
            if ($prop['annotation'] == 'embedded' && isset($prop['property_multiple']) && $prop['property_multiple']) {
                $fields[] = sprintf('%s$this->%s = new Collection();', $this->spaces, $prop['field_name']);
            }
        }

        return $this->prefixWithSpaces(
            str_replace('<fields>', implode("\n", $fields), $this->constructorTemplate)
        ) . "\n";
    }
882005
protected function onMetaReceived($metaData)
    {
        if (is_array($this->params)) {
            foreach ($this->params as $columnName => $columnInfo) {
                if (isset($metaData["columns"][$columnName])) {
                    $newColumnName = Utility::get($columnInfo, "name");
                    $currentColumnInfo = $metaData["columns"][$columnName];
                    if ($newColumnName) {
                        unset($columnInfo["name"]);
                        unset($metaData["columns"][$columnName]);
                    }

                    if ($this->override) {
                        $metaData["columns"][($newColumnName) ? $newColumnName : $columnName] = $columnInfo;
                    } else {
                        $metaData["columns"][($newColumnName) ? $newColumnName : $columnName] = array_merge($currentColumnInfo, $columnInfo);
                    }
                }
            }
        } else if (is_callable($this->params)) {
            $func = $this->params;
            $columns = $metaData['columns'];
            $pos = 0;
            foreach ($columns as $c => $cMeta) {
                $newMeta = $func($c, $cMeta, $pos);
                if (isset($newMeta['name'])) {
                    $newName = $newMeta['name'];
                    $this->nameMap[$c] = $newName;
                    // unset($columns[$c]);
                    unset($newMeta['name']);
                    $columns[$newName] = $newMeta;
                } else {
                    $columns[$c] = $newMeta;
                }
                $pos++;
            }
            $metaData['columns'] = $columns;
        }
        return $metaData;
    }
670162
private function createAttributeNode(PropertyMetadata $metadata, string $attributeName): \DOMAttr
    {
        if ($namespace = (string) $metadata->xmlNamespace) {
            $prefix = $this->lookupPrefix($namespace);
            $node = $this->document->createAttributeNS($namespace, $prefix.':'.$attributeName);
        } else {
            $node = $this->document->createAttribute($attributeName);
        }

        return $node;
    }
578165
public function metadata($metadata = null) {
        if ($metadata === null) {
            return $this->metadata;
        }

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

        return $this;
    }
75372
private function serialize(EntityMetadata $metadata)
    {
        switch ($this->serializer) {
            case self::SERIALIZER_PHP:
                return serialize($metadata);
            case self::SERIALIZER_IGBINARY:
                return igbinary_serialize($metadata);
            default:
                throw new RuntimeException('Unable to handle serialization of the metadata object');
        }
    }
1324260
protected function generateEntityClassName(ClassMetadataInfo $metadata)
    {
        return 'class ' . $this->getClassName($metadata) .
        ($this->extendsClass() ? ' extends ' . $this->getClassToExtendName() : null) .
        ($this->interfaceClass() ? ' implements ' . $this->getClassToInterfaceName() : null);
    }
1283354
public function create_metadata_educational($met, DOMDocument  &$doc, $xmlnode) {
        $metadata = $doc->createElementNS($this->ccnamespaces['imscc'], 'metadata');
        $xmlnode->insertBefore($metadata, $xmlnode->firstChild);
        $lom = $doc->createElementNS($this->ccnamespaces['lom'], 'lom');
        $metadata->appendChild($lom);
        $educational = $doc->createElementNS($this->ccnamespaces['lom'], 'educational');
        $lom->appendChild($educational);

        foreach ($met->arrayeducational as $value) {
            !is_array($value) ? $value = array($value) : null;
            foreach ($value as $v) {
                $userrole = $doc->createElementNS($this->ccnamespaces['lom'], 'intendedEndUserRole');
                $educational->appendChild($userrole);
                $nd4 = $doc->createElementNS($this->ccnamespaces['lom'], 'source', 'IMSGLC_CC_Rolesv1p1');
                $nd5 = $doc->createElementNS($this->ccnamespaces['lom'], 'value', $v[0]);
                $userrole->appendChild($nd4);
                $userrole->appendChild($nd5);
            }
        }
        return $metadata;
    }
880375
protected function generateEntityClassName(ClassMetadataInfo $metadata)
    {
        return 'class ' . $this->getClassName($metadata) .
            ($this->extendsClass() ? ' extends ' . $this->getClassToExtendName() : null);
    }
657994
private function generateDocumentMethod(array $metadata, $template)
    {
        return $this->prefixWithSpaces(
            str_replace(
                ['<methodName>', '<fieldName>'],
                [ucfirst($metadata['field_name']), $metadata['field_name']],
                $template
            )
        );
    }
1321731
public function create(array $metadata)
    {
        $schema = $this->getSchemaFromMetadata($metadata);

        $statements = $schema->toSql($this->platform);

        $this->build($statements);

        return $statements;
    }
523672
protected function create_metadata_file(cc_i_metadata_file $met, DOMDocument &$doc, $xmlnode = null) {

        $dnode = $doc->createElementNS($this->ccnamespaces['lom'], "lom");

        !empty($xmlnode) ? $xmlnode->appendChild($dnode) : null;
        !empty($met->arrayeducational) ? $this->create_metadata_educational($met, $doc, $dnode) : null;

        return $dnode;
    }
1238108
private function sanitizeMetaDataId(array $metaData): string
    {
        $metaDataId = $metaData[static::METADATA_ID] ?? '';
        if ('' === $metaDataId) {
            $message = 'No metadata key "id" was not found in ' . $this->filePath;

            $event = new BadMetaDataFoundEvent($this->filePath, $message);
            $this->eventDispatcher->dispatch($event::NAME, $event);

            $metaDataId = trim(basename($this->getModuleDirectoryName()), DIRECTORY_SEPARATOR);
        }

        return $metaDataId;
    }
52127
protected function createDocument($data = array())
    {
        $enginePage = $this->getServiceLocator()->get('MelisEngineTree');
        $translator = $this->getServiceLocator()->get('translator');
        $pageSvc    = $this->getServiceLocator()->get('MelisEnginePage');
        $doc = new Document();
        if(is_array($data)) {
            $uri = $enginePage->getPageLink($data['page_id'], true);
            $pattern = '/(http|https)\:\/\/(www\.)?[a-zA-Z0-9-_.]+(\.([a-z.])?)*/';
            $domain = $this->getCurrentDomain();
            if($domain === '/'){
             echo  getenv('MELIS_PLATFORM') . " configuration is incorrect or does not exists in db";
             die;
           }
            if(!preg_match($pattern, $uri)) {
                $uri = $domain . $uri;
            }

            #$pageContent = $this->getUrlContent($uri) -- old ;

            $pageId = $data['page_id'] ?? null;
            $pageData  = $pageSvc->getDatasPage($pageId);
            $melisPageTree  = $pageData->getMelisPageTree();
            $pageContent = $melisPageTree->page_content;

            if($pageContent) {

                $doc->addField(Document\Field::Text('description', $enginePage->cleanString($this->getHtmlDescription($pageContent))));
                $doc->addField(Document\Field::Keyword('url', $uri));
                $doc->addField(Document\Field::Keyword('page_id', $data['page_id']));
                $doc->addField(Document\Field::Keyword('page_name', $data['page_name']));
                $doc->addField(Document\Field::UnStored('contents', $pageContent));


                $this->tmpLogs .= 'OK ' . sprintf($translator->translate('tr_melis_engine_search_create_index'), $data['page_id']) . sprintf($translator->translate('tr_melis_engine_search_create_index_success'), $uri) . PHP_EOL . '<br/>';
            }
            else {
                $this->tmpLogs .= 'KO ' . sprintf($translator->translate('tr_melis_engine_search_create_index'), $data['page_id']) . $translator->translate('tr_melis_engine_search_create_index_fail_unreachable') . ', ' . $uri . PHP_EOL . '<br/>';
                $this->unreachableCount++;
            }

        }

        return $doc;

    }
240607
private function instantiateFromMetadata(Metadata $metadata)
    {
        $class = $metadata->getClass();

        if (!class_exists($class)) {
            throw new \RuntimeException(sprintf(
                'Document class "%s" does not exist', $class
            ));
        }

        $document = new $class();

        return $document;
    }
670359
public function generate(ClassMetadata $classMetadata): string
    {
        $phpFile = new PhpFile();
        $phpFile->setStrictTypes(true);

        $namespace = $phpFile->addNamespace($this->configuration->getNamespaceForClass($classMetadata));

        $class = $namespace
            ->addClass($this->configuration->getClassName($classMetadata))
            ->setComment('THIS CLASS WAS GENERATED BY THE SERIALIZER. DO NOT EDIT THIS FILE.')
            ->setFinal(true)
            ->setImplements([HydratorInterface::class, SerializerAwareInterface::class, ObjectInstantiatorAwareInterface::class]);

        if (null !== $classMetadata->baseClass) {
            $class->addExtend($classMetadata->baseClass);
        }

        $class->addTrait(SerializerAwareTrait::class);
        $class->addTrait(ObjectInstantiatorAwareTrait::class);

        foreach ($this->decorators as $decorator) {
            $decorator->decorate($phpFile, $namespace, $class, $classMetadata);
        }

        return $this->printer->printFile($phpFile);
    }
724377
public function setMetaData($metaData) {
		if (is_array($metaData) && empty($metaData)) {
			$this->metaData = new \stdClass;
		} else {
			$this->metaData = $metaData;
		}

		return $this;
	}
129492
protected function prepareOptions(Metadata $metadata)
	{
		$options = array(
			'tags'  => array_merge_recursive($metadata->getTags(), array(
				'releaseStage' => $metadata->getStage(),
				'appVersion'   => $metadata->getAppVersion(),
			)),
			'extra' => array_merge_recursive($metadata->getMetadata(), array(
				'appRootDir'   => $metadata->getAppRootDir(),
				'releaseStage' => $metadata->getStage(),
				'appVersion'   => $metadata->getAppVersion(),
			)),
			'level' => self::$SEVERITY_MAP[$metadata->getSeverity()],
		);

		$groupingHash = $this->calculateGroupingHash($metadata);
		if ($groupingHash)
		{
			$options['checksum'] = $groupingHash;
		}

		return $options;
	}