Small corrections
This commit is contained in:
parent
fb823d6033
commit
bfb02a1205
|
@ -77,7 +77,7 @@
|
||||||
"@php bin/cli orm:clear-cache:result --flush"
|
"@php bin/cli orm:clear-cache:result --flush"
|
||||||
],
|
],
|
||||||
"doctrine:initialize-database": [
|
"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 bin/cli oai:formats:update --quiet"
|
||||||
],
|
],
|
||||||
"php-cs-fixer:check": [
|
"php-cs-fixer:check": [
|
||||||
|
|
|
@ -21,8 +21,8 @@ adminEmail: 'admin@example.org'
|
||||||
#
|
#
|
||||||
# Database connection details
|
# Database connection details
|
||||||
#
|
#
|
||||||
# This has to be a valid data source name (DSN) URL. The scheme is used to
|
# 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 URL encode user and password
|
# 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
|
# 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
|
# 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).
|
# removed so add an extra slash to specify an absolute file path for SQLite).
|
||||||
|
|
|
@ -130,7 +130,8 @@ class Configuration
|
||||||
*
|
*
|
||||||
* @return array<TKey, TValue> The configuration array
|
* @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
|
protected function loadConfigFile(): array
|
||||||
{
|
{
|
||||||
|
@ -159,7 +160,8 @@ class Configuration
|
||||||
/**
|
/**
|
||||||
* Load and validate configuration settings from YAML file.
|
* 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()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
|
@ -78,6 +78,9 @@ abstract class Middleware extends AbstractMiddleware
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The constructor must have the same signature for all derived classes, thus make it final.
|
||||||
|
*/
|
||||||
final public function __construct()
|
final public function __construct()
|
||||||
{
|
{
|
||||||
// Make constructor final to avoid issues in dispatcher.
|
// Make constructor final to avoid issues in dispatcher.
|
||||||
|
|
|
@ -85,7 +85,8 @@ class Dispatcher extends AbstractMiddleware
|
||||||
protected function processRequest(ServerRequestInterface $request): ServerRequestInterface
|
protected function processRequest(ServerRequestInterface $request): ServerRequestInterface
|
||||||
{
|
{
|
||||||
$request = $this->getRequestWithAttributes($request);
|
$request = $this->getRequestWithAttributes($request);
|
||||||
if (!ErrorHandler::getInstance()->hasErrors()) {
|
$errorHandler = ErrorHandler::getInstance();
|
||||||
|
if (!$errorHandler->hasErrors()) {
|
||||||
/** @var string */
|
/** @var string */
|
||||||
$verb = $request->getAttribute('verb');
|
$verb = $request->getAttribute('verb');
|
||||||
$middleware = __NAMESPACE__ . '\\' . $verb;
|
$middleware = __NAMESPACE__ . '\\' . $verb;
|
||||||
|
@ -93,7 +94,7 @@ class Dispatcher extends AbstractMiddleware
|
||||||
$this->requestHandler->queue->enqueue(new $middleware());
|
$this->requestHandler->queue->enqueue(new $middleware());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->requestHandler->queue->enqueue(ErrorHandler::getInstance());
|
$this->requestHandler->queue->enqueue($errorHandler);
|
||||||
return $request;
|
return $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,6 +115,7 @@ class Dispatcher extends AbstractMiddleware
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate the request parameters.
|
* Validate the request parameters.
|
||||||
|
*
|
||||||
* @see https://openarchives.org/OAI/openarchivesprotocol.html#ProtocolMessages
|
* @see https://openarchives.org/OAI/openarchivesprotocol.html#ProtocolMessages
|
||||||
*
|
*
|
||||||
* @param string[] $arguments The request parameters
|
* @param string[] $arguments The request parameters
|
||||||
|
@ -122,11 +124,12 @@ class Dispatcher extends AbstractMiddleware
|
||||||
*/
|
*/
|
||||||
protected function validateArguments(array $arguments): bool
|
protected function validateArguments(array $arguments): bool
|
||||||
{
|
{
|
||||||
|
$errorHandler = ErrorHandler::getInstance();
|
||||||
if (
|
if (
|
||||||
count(array_diff(array_keys($arguments), self::OAI_PARAMS)) !== 0
|
count(array_diff(array_keys($arguments), self::OAI_PARAMS)) !== 0
|
||||||
or !isset($arguments['verb'])
|
or !isset($arguments['verb'])
|
||||||
) {
|
) {
|
||||||
ErrorHandler::getInstance()->withError('badArgument');
|
$errorHandler->withError('badArgument');
|
||||||
} else {
|
} else {
|
||||||
switch ($arguments['verb']) {
|
switch ($arguments['verb']) {
|
||||||
case 'GetRecord':
|
case 'GetRecord':
|
||||||
|
@ -135,12 +138,12 @@ class Dispatcher extends AbstractMiddleware
|
||||||
or !isset($arguments['identifier'])
|
or !isset($arguments['identifier'])
|
||||||
or !isset($arguments['metadataPrefix'])
|
or !isset($arguments['metadataPrefix'])
|
||||||
) {
|
) {
|
||||||
ErrorHandler::getInstance()->withError('badArgument');
|
$errorHandler->withError('badArgument');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'Identify':
|
case 'Identify':
|
||||||
if (count($arguments) !== 1) {
|
if (count($arguments) !== 1) {
|
||||||
ErrorHandler::getInstance()->withError('badArgument');
|
$errorHandler->withError('badArgument');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'ListIdentifiers':
|
case 'ListIdentifiers':
|
||||||
|
@ -153,30 +156,30 @@ class Dispatcher extends AbstractMiddleware
|
||||||
(isset($arguments['resumptionToken']) && count($arguments) !== 2)
|
(isset($arguments['resumptionToken']) && count($arguments) !== 2)
|
||||||
or isset($arguments['identifier'])
|
or isset($arguments['identifier'])
|
||||||
) {
|
) {
|
||||||
ErrorHandler::getInstance()->withError('badArgument');
|
$errorHandler->withError('badArgument');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ErrorHandler::getInstance()->withError('badArgument');
|
$errorHandler->withError('badArgument');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'ListMetadataFormats':
|
case 'ListMetadataFormats':
|
||||||
if (count($arguments) !== 1) {
|
if (count($arguments) !== 1) {
|
||||||
if (!isset($arguments['identifier']) || count($arguments) !== 2) {
|
if (!isset($arguments['identifier']) || count($arguments) !== 2) {
|
||||||
ErrorHandler::getInstance()->withError('badArgument');
|
$errorHandler->withError('badArgument');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'ListSets':
|
case 'ListSets':
|
||||||
if (count($arguments) !== 1) {
|
if (count($arguments) !== 1) {
|
||||||
if (!isset($arguments['resumptionToken']) || count($arguments) !== 2) {
|
if (!isset($arguments['resumptionToken']) || count($arguments) !== 2) {
|
||||||
ErrorHandler::getInstance()->withError('badArgument');
|
$errorHandler->withError('badArgument');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ErrorHandler::getInstance()->withError('badVerb');
|
$errorHandler->withError('badVerb');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return !ErrorHandler::getInstance()->hasErrors();
|
return !$errorHandler->hasErrors();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ class ErrorHandler extends AbstractMiddleware
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of defined OAI-PMH errors.
|
* List of defined OAI-PMH errors.
|
||||||
|
*
|
||||||
* @see https://openarchives.org/OAI/openarchivesprotocol.html#ErrorConditions
|
* @see https://openarchives.org/OAI/openarchivesprotocol.html#ErrorConditions
|
||||||
*/
|
*/
|
||||||
protected const OAI_ERRORS = [
|
protected const OAI_ERRORS = [
|
||||||
|
@ -109,7 +110,7 @@ class ErrorHandler extends AbstractMiddleware
|
||||||
*
|
*
|
||||||
* @return ErrorHandler The ErrorHandler instance
|
* @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
|
public function withError(string $errorCode): ErrorHandler
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue