First draft
This commit is contained in:
68
src/OAI/Verb/ListMetadataFormats.php
Normal file
68
src/OAI/Verb/ListMetadataFormats.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user