First draft

This commit is contained in:
2026-04-30 16:08:01 +02:00
parent 7ce97c0c55
commit e09a9fc2a6
21 changed files with 7137 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
namespace App\OAI\Verb;
use App\OAI\OaiBase;
use App\OAI\OaiError;
use AC\DB\Connection;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
/**
* Represents a ListMetadataFormats response
*/
final class ListMetadataFormats
{
public function __construct(
private Serializer $serializer = new Serializer(),
)
{
$this->serializer = new Serializer(
[new ObjectNormalizer()],
[new XmlEncoder()]
);
}
/**
* Returns the XML response
*/
public function response(): string
{
$formats = $this->getValidFormats();
$content = $this->serializer->encode(
['metadataFormat' => [...$formats]],
'xml',
[
'xml_format_output' => true,
'xml_root_node_name' => 'ListMetadataFormats',
// Don't include the XML declaration, handled by OaiBase
'encoder_ignored_node_types' => [
\XML_PI_NODE,
],
]
);
return OaiBase::create($content, 'ListMetadataFormats');
}
/**
* @return array<int,array<string,mixed>>
*/
private function getValidFormats(): array
{
$dbConn = Connection::new();
$queryBuilder = $dbConn->createQueryBuilder();
$formats = $queryBuilder->select(
'prefix as metadataPrefix',
'schemaLoc as schema',
'namespace as metadataNamespace',
)
->from('metadata_formats')
->fetchAllAssociative();
return $formats;
}
}