From 1e275422bf7918c91fb9c0c712ae00c880866c96 Mon Sep 17 00:00:00 2001 From: Sebastian Meyer Date: Sat, 6 Jan 2024 16:31:19 +0100 Subject: [PATCH] Handle metadata formats as entities --- src/Database.php | 6 +++--- src/Middleware/GetRecord.php | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Database.php b/src/Database.php index b8556ff..7b54da3 100644 --- a/src/Database.php +++ b/src/Database.php @@ -219,17 +219,17 @@ class Database * Get a single record. * * @param string $identifier The record identifier - * @param string $metadataPrefix The metadata prefix + * @param Format $format The metadata format * * @return ?Record The record or NULL on failure */ - public function getRecord(string $identifier, string $metadataPrefix): ?Record + public function getRecord(string $identifier, Format $format): ?Record { return $this->entityManager->find( Record::class, [ 'identifier' => $identifier, - 'format' => $metadataPrefix + 'format' => $format ] ); } diff --git a/src/Middleware/GetRecord.php b/src/Middleware/GetRecord.php index 607670b..6249d20 100644 --- a/src/Middleware/GetRecord.php +++ b/src/Middleware/GetRecord.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace OCC\OaiPmh2\Middleware; use OCC\OaiPmh2\Database; +use OCC\OaiPmh2\Database\Format; use OCC\OaiPmh2\Document; use OCC\OaiPmh2\Middleware; use Psr\Http\Message\ServerRequestInterface; @@ -46,7 +47,9 @@ class GetRecord extends Middleware protected function prepareResponse(ServerRequestInterface $request): void { $params = $request->getAttributes(); - $oaiRecord = Database::getInstance()->getRecord($params['identifier'], $params['metadataPrefix']); + /** @var Format */ + $format = Database::getInstance()->getEntityManager()->getReference(Format::class, $params['metadataPrefix']); + $oaiRecord = Database::getInstance()->getRecord($params['identifier'], $format); if (!isset($oaiRecord)) { if (Database::getInstance()->idDoesExist($params['identifier'])) {