Small corrections

This commit is contained in:
Sebastian Meyer 2024-07-20 12:00:15 +02:00
parent fb823d6033
commit bfb02a1205
6 changed files with 26 additions and 17 deletions

View File

@ -77,7 +77,7 @@
"@php bin/cli orm:clear-cache:result --flush"
],
"doctrine:initialize-database": [
"@php bin/cli orm:schema-tool:update --complete --force",
"@php bin/cli orm:schema-tool:update --force",
"@php bin/cli oai:formats:update --quiet"
],
"php-cs-fixer:check": [

View File

@ -21,8 +21,8 @@ adminEmail: 'admin@example.org'
#
# Database connection details
#
# This has to be a valid data source name (DSN) URL. The scheme is used to
# specify a driver, the user and password in the URL encode user and password
# This has to be a valid data source name (DSN) URI. The scheme is used to
# specify a driver, the user and password in the URI encode user and password
# for the connection, followed by the host and port parts. The path after the
# authority part represents the name of the database (the leading slash is
# removed so add an extra slash to specify an absolute file path for SQLite).

View File

@ -130,7 +130,8 @@ class Configuration
*
* @return array<TKey, TValue> The configuration array
*
* @throws FileNotFoundException|ValidationFailedException
* @throws FileNotFoundException if configuration file does not exist
* @throws ValidationFailedException if configuration file is not valid
*/
protected function loadConfigFile(): array
{
@ -159,7 +160,8 @@ class Configuration
/**
* Load and validate configuration settings from YAML file.
*
* @throws FileNotFoundException | ValidationFailedException
* @throws FileNotFoundException if configuration file does not exist
* @throws ValidationFailedException if configuration file is not valid
*/
private function __construct()
{

View File

@ -78,6 +78,9 @@ abstract class Middleware extends AbstractMiddleware
return $response;
}
/**
* The constructor must have the same signature for all derived classes, thus make it final.
*/
final public function __construct()
{
// Make constructor final to avoid issues in dispatcher.

View File

@ -85,7 +85,8 @@ class Dispatcher extends AbstractMiddleware
protected function processRequest(ServerRequestInterface $request): ServerRequestInterface
{
$request = $this->getRequestWithAttributes($request);
if (!ErrorHandler::getInstance()->hasErrors()) {
$errorHandler = ErrorHandler::getInstance();
if (!$errorHandler->hasErrors()) {
/** @var string */
$verb = $request->getAttribute('verb');
$middleware = __NAMESPACE__ . '\\' . $verb;
@ -93,7 +94,7 @@ class Dispatcher extends AbstractMiddleware
$this->requestHandler->queue->enqueue(new $middleware());
}
}
$this->requestHandler->queue->enqueue(ErrorHandler::getInstance());
$this->requestHandler->queue->enqueue($errorHandler);
return $request;
}
@ -114,6 +115,7 @@ class Dispatcher extends AbstractMiddleware
/**
* Validate the request parameters.
*
* @see https://openarchives.org/OAI/openarchivesprotocol.html#ProtocolMessages
*
* @param string[] $arguments The request parameters
@ -122,11 +124,12 @@ class Dispatcher extends AbstractMiddleware
*/
protected function validateArguments(array $arguments): bool
{
$errorHandler = ErrorHandler::getInstance();
if (
count(array_diff(array_keys($arguments), self::OAI_PARAMS)) !== 0
or !isset($arguments['verb'])
) {
ErrorHandler::getInstance()->withError('badArgument');
$errorHandler->withError('badArgument');
} else {
switch ($arguments['verb']) {
case 'GetRecord':
@ -135,12 +138,12 @@ class Dispatcher extends AbstractMiddleware
or !isset($arguments['identifier'])
or !isset($arguments['metadataPrefix'])
) {
ErrorHandler::getInstance()->withError('badArgument');
$errorHandler->withError('badArgument');
}
break;
case 'Identify':
if (count($arguments) !== 1) {
ErrorHandler::getInstance()->withError('badArgument');
$errorHandler->withError('badArgument');
}
break;
case 'ListIdentifiers':
@ -153,30 +156,30 @@ class Dispatcher extends AbstractMiddleware
(isset($arguments['resumptionToken']) && count($arguments) !== 2)
or isset($arguments['identifier'])
) {
ErrorHandler::getInstance()->withError('badArgument');
$errorHandler->withError('badArgument');
}
} else {
ErrorHandler::getInstance()->withError('badArgument');
$errorHandler->withError('badArgument');
}
break;
case 'ListMetadataFormats':
if (count($arguments) !== 1) {
if (!isset($arguments['identifier']) || count($arguments) !== 2) {
ErrorHandler::getInstance()->withError('badArgument');
$errorHandler->withError('badArgument');
}
}
break;
case 'ListSets':
if (count($arguments) !== 1) {
if (!isset($arguments['resumptionToken']) || count($arguments) !== 2) {
ErrorHandler::getInstance()->withError('badArgument');
$errorHandler->withError('badArgument');
}
}
break;
default:
ErrorHandler::getInstance()->withError('badVerb');
$errorHandler->withError('badVerb');
}
}
return !ErrorHandler::getInstance()->hasErrors();
return !$errorHandler->hasErrors();
}
}

View File

@ -42,6 +42,7 @@ class ErrorHandler extends AbstractMiddleware
/**
* List of defined OAI-PMH errors.
*
* @see https://openarchives.org/OAI/openarchivesprotocol.html#ErrorConditions
*/
protected const OAI_ERRORS = [
@ -109,7 +110,7 @@ class ErrorHandler extends AbstractMiddleware
*
* @return ErrorHandler The ErrorHandler instance
*
* @throws DomainException
* @throws DomainException if error code is not a valid OAI-PMH error
*/
public function withError(string $errorCode): ErrorHandler
{