68 lines
1.7 KiB
PHP
68 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OaiSymfony\OAI\Verb;
|
|
|
|
use OaiSymfony\OAI\OaiBase;
|
|
use OaiSymfony\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;
|
|
}
|
|
} |