Skip to content

Commit

Permalink
Small corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-meyer committed Jul 20, 2024
1 parent fb823d6 commit bfb02a1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
4 changes: 2 additions & 2 deletions config/config.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ adminEmail: '[email protected]'
#
# 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).
Expand Down
6 changes: 4 additions & 2 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ protected function getValidationConstraints(): Assert\Collection
*
* @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
{
Expand Down Expand Up @@ -159,7 +160,8 @@ protected function loadConfigFile(): array
/**
* 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()
{
Expand Down
3 changes: 3 additions & 0 deletions src/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ protected function processResponse(ResponseInterface $response): ResponseInterfa
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.
Expand Down
25 changes: 14 additions & 11 deletions src/Middleware/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,16 @@ protected function getRequestWithAttributes(ServerRequestInterface $request): Se
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;
if (is_a($middleware, Middleware::class, true)) {
$this->requestHandler->queue->enqueue(new $middleware());
}
}
$this->requestHandler->queue->enqueue(ErrorHandler::getInstance());
$this->requestHandler->queue->enqueue($errorHandler);
return $request;
}

Expand All @@ -114,6 +115,7 @@ protected function processResponse(ResponseInterface $response): ResponseInterfa

/**
* Validate the request parameters.
*
* @see https://openarchives.org/OAI/openarchivesprotocol.html#ProtocolMessages
*
* @param string[] $arguments The request parameters
Expand All @@ -122,11 +124,12 @@ protected function processResponse(ResponseInterface $response): ResponseInterfa
*/
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':
Expand All @@ -135,12 +138,12 @@ protected function validateArguments(array $arguments): bool
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':
Expand All @@ -153,30 +156,30 @@ protected function validateArguments(array $arguments): bool
(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();
}
}
3 changes: 2 additions & 1 deletion src/Middleware/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -109,7 +110,7 @@ protected function processResponse(ResponseInterface $response): ResponseInterfa
*
* @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
{
Expand Down

0 comments on commit bfb02a1

Please sign in to comment.