diff --git a/composer.json b/composer.json index b996cc2..f273ba1 100644 --- a/composer.json +++ b/composer.json @@ -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": [ diff --git a/config/config.dist.yml b/config/config.dist.yml index 0017c78..bbcf2f3 100644 --- a/config/config.dist.yml +++ b/config/config.dist.yml @@ -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). diff --git a/src/Configuration.php b/src/Configuration.php index 30cbab6..d69d651 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -130,7 +130,8 @@ class Configuration * * @return array 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() { diff --git a/src/Middleware.php b/src/Middleware.php index 10e8c56..8ca7538 100644 --- a/src/Middleware.php +++ b/src/Middleware.php @@ -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. diff --git a/src/Middleware/Dispatcher.php b/src/Middleware/Dispatcher.php index 1259088..101272e 100644 --- a/src/Middleware/Dispatcher.php +++ b/src/Middleware/Dispatcher.php @@ -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(); } } diff --git a/src/Middleware/ErrorHandler.php b/src/Middleware/ErrorHandler.php index ce28f43..129ebf5 100644 --- a/src/Middleware/ErrorHandler.php +++ b/src/Middleware/ErrorHandler.php @@ -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 {