src/POData/Writers/Metadata/MetadataWriter.php
/**
     * Write the metadata in CSDL format.
     * 
     * @return string
     */
Write the metadata in CSDL format.

@return string
Write the metadata in CSDL format . @return string
public function writeMetadata()
    {   
       $this->_metadataManager = MetadataManager::create($this->providersWrapper);
        $this->_dataServiceVersion = new Version(1, 0);
        $edmSchemaVersion = $this->providersWrapper->getEdmSchemaVersion();
        $this->_metadataManager->getDataServiceAndEdmSchemaVersions($this->_dataServiceVersion, $edmSchemaVersion);
        $this->_xmlWriter = new \XMLWriter();
        $this->_xmlWriter->openMemory();
        $this->_xmlWriter->setIndent(4);
        $this->_writeTopLevelElements($this->_dataServiceVersion->toString());
        $resourceTypesInContainerNamespace = array();
        $containerNamespace = $this->providersWrapper->getContainerNamespace();
        foreach ($this->_metadataManager->getResourceTypesAlongWithNamespace() as $resourceTypeNamespace => $resourceTypesWithName) {
            if ($resourceTypeNamespace == $containerNamespace) {                
                foreach ($resourceTypesWithName as $resourceTypeName => $resourceType) {
                    $resourceTypesInContainerNamespace[] = $resourceType;
                }
            } else {
                $associationsInThisNamespace = $this->_metadataManager->getResourceAssociationTypesForNamespace($resourceTypeNamespace);
                $this->_writeSchemaElement($resourceTypeNamespace, $edmSchemaVersion);
                $uniqueAssociationsInThisNamespace = $this->_metadataManager->getUniqueResourceAssociationTypesForNamespace($resourceTypeNamespace);
                $this->_writeResourceTypes(array_values($resourceTypesWithName), $associationsInThisNamespace);
                $this->_writeAssociationTypes($uniqueAssociationsInThisNamespace);
            }            
        }
        $this->_writeSchemaElement($resourceTypeNamespace, $edmSchemaVersion);
        if (!empty($resourceTypesInContainerNamespace)) {
            $associationsInThisNamespace = $this->_metadataManager->getResourceAssociationTypesForNamespace($containerNamespace);
            $uniqueAssociationsInThisNamespace = $this->_metadataManager->getUniqueResourceAssociationTypesForNamespace($containerNamespace);
            $this->_writeResourceTypes($resourceTypesInContainerNamespace, $associationsInThisNamespace);
            $this->_writeAssociationTypes($uniqueAssociationsInThisNamespace);
        }
        $this->_writeEntityContainer();
        $this->_xmlWriter->endElement();
        $this->_xmlWriter->endElement();
        $this->_xmlWriter->endElement();
        $metadataInCsdl = $this->_xmlWriter->outputMemory(true);
        return $metadataInCsdl;
    }
public function writeMetadata ( ) { $ this -> _metadataManager = MetadataManager :: create ( $ this -> providersWrapper ) ; $ this -> _dataServiceVersion = new Version ( 1 , 0 ) ; $ edmSchemaVersion = $ this -> providersWrapper -> getEdmSchemaVersion ( ) ; $ this -> _metadataManager -> getDataServiceAndEdmSchemaVersions ( $ this -> _dataServiceVersion , $ edmSchemaVersion ) ; $ this -> _xmlWriter = new \ XMLWriter ( ) ; $ this -> _xmlWriter -> openMemory ( ) ; $ this -> _xmlWriter -> setIndent ( 4 ) ; $ this -> _writeTopLevelElements ( $ this -> _dataServiceVersion -> toString ( ) ) ; $ resourceTypesInContainerNamespace = array ( ) ; $ containerNamespace = $ this -> providersWrapper -> getContainerNamespace ( ) ; foreach ( $ this -> _metadataManager -> getResourceTypesAlongWithNamespace ( ) as $ resourceTypeNamespace => $ resourceTypesWithName ) { if ( $ resourceTypeNamespace == $ containerNamespace ) { foreach ( $ resourceTypesWithName as $ resourceTypeName => $ resourceType ) { $ resourceTypesInContainerNamespace [ ] = $ resourceType ; } } else { $ associationsInThisNamespace = $ this -> _metadataManager -> getResourceAssociationTypesForNamespace ( $ resourceTypeNamespace ) ; $ this -> _writeSchemaElement ( $ resourceTypeNamespace , $ edmSchemaVersion ) ; $ uniqueAssociationsInThisNamespace = $ this -> _metadataManager -> getUniqueResourceAssociationTypesForNamespace ( $ resourceTypeNamespace ) ; $ this -> _writeResourceTypes ( array_values ( $ resourceTypesWithName ) , $ associationsInThisNamespace ) ; $ this -> _writeAssociationTypes ( $ uniqueAssociationsInThisNamespace ) ; } } $ this -> _writeSchemaElement ( $ resourceTypeNamespace , $ edmSchemaVersion ) ; if ( ! empty ( $ resourceTypesInContainerNamespace ) ) { $ associationsInThisNamespace = $ this -> _metadataManager -> getResourceAssociationTypesForNamespace ( $ containerNamespace ) ; $ uniqueAssociationsInThisNamespace = $ this -> _metadataManager -> getUniqueResourceAssociationTypesForNamespace ( $ containerNamespace ) ; $ this -> _writeResourceTypes ( $ resourceTypesInContainerNamespace , $ associationsInThisNamespace ) ; $ this -> _writeAssociationTypes ( $ uniqueAssociationsInThisNamespace ) ; } $ this -> _writeEntityContainer ( ) ; $ this -> _xmlWriter -> endElement ( ) ; $ this -> _xmlWriter -> endElement ( ) ; $ this -> _xmlWriter -> endElement ( ) ; $ metadataInCsdl = $ this -> _xmlWriter -> outputMemory ( true ) ; return $ metadataInCsdl ; }
Write the metadata in CSDL format.
Write the metadata in CSDL format .
//write Container schema node and define required nmaespaces //Get assocation types in container namespace as array of  //key-value pairs (with key as association type //lookup key i.e. ResourceType::Name_NavigationProperty::Name.  //Same association will appear twice for di-directional relationship  //(duplicate value will be there in this case) //Get association type in container namespace as array of unique values //End container Schema node //End edmx:Edmx and edmx:DataServices nodes