verb = $verb; $this->identifier = $identifier; preg_match("/oai:www.yourdomain.com(:|\/)(?P.*):(?P\d+)$/", $identifier, $matches); $classMetadataFactory = new ClassMetadataFactory(new AttributeLoader()); $metadataAwareNameConverter = new MetadataAwareNameConverter($classMetadataFactory); $this->serializer = new Serializer( [new ObjectNormalizer($classMetadataFactory, $metadataAwareNameConverter)], [new XmlEncoder()] ); } /** * Map DB record data to object attributes for serialization */ private function mapData(array $record): void { // Implement } /** * Return an XML representation of a DB record * in a given format */ public function toXML(): string { $record = []; // This represents a record from the database if ($record === null) { throw new IdentifierNotFoundException($this->identifier); } $this->mapData($record); $normal = $this->serializer->normalize($this); $data = [ '@xmlns:oai_dc' => "http://www.openarchives.org/OAI/2.0/oai_dc/", '@xmlns:dc' => "http://purl.org/dc/elements/1.1/", '#' => $normal ]; $oai_dc = ['oai_dc:dc' => $data]; if (isset($record['relation'])) { $oai_dc['oai_dc:dc']['dc:relation'] = $record['relation']; } $header = [ 'identifier' => $this->identifier, 'datestamp' => $record['datestamp'], 'setSpec' => $record['setSpec'], ]; // Adapt for ListRecords... $record = $this->verb === 'GetRecord' ? ['record' => ['header' => $header, 'metadata' => $oai_dc]] : ['header' => $header, 'metadata' => $oai_dc]; $content = $this->serializer->encode( $record, 'xml', [ 'xml_format_output' => true, 'xml_root_node_name' => $this->verb === 'GetRecord' ? $this->verb : 'record', // Don't include the XML declaration, handled by OaiBase 'encoder_ignored_node_types' => [ \XML_PI_NODE, ], ] ); return $content; } }