only error codes defined by the OAI-PMH protocol
This commit is contained in:
parent
7d9c86c70a
commit
e18e5fff48
12
oai2.php
12
oai2.php
|
@ -60,7 +60,7 @@ $oai2 = new OAI2Server($uri, $args, $identifyResponse,
|
||||||
'ListMetadataFormats' =>
|
'ListMetadataFormats' =>
|
||||||
function($identifier = '') {
|
function($identifier = '') {
|
||||||
if (!empty($identifier) && $identifier != 'a.b.c') {
|
if (!empty($identifier) && $identifier != 'a.b.c') {
|
||||||
throw new OAI2Exception('idDoesNotExist', '', $identifier);
|
throw new OAI2Exception('idDoesNotExist');
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
array('rif' => array('metadataPrefix'=>'rif',
|
array('rif' => array('metadataPrefix'=>'rif',
|
||||||
|
@ -95,18 +95,22 @@ $oai2 = new OAI2Server($uri, $args, $identifyResponse,
|
||||||
|
|
||||||
'ListRecords' =>
|
'ListRecords' =>
|
||||||
function($metadataPrefix, $from = '', $until = '', $set = '', $count = false, $deliveredRecords = 0, $maxItems = 0) use ($example_record) {
|
function($metadataPrefix, $from = '', $until = '', $set = '', $count = false, $deliveredRecords = 0, $maxItems = 0) use ($example_record) {
|
||||||
// throws new OAI2Exception('noRecordsMatch')
|
|
||||||
// throws new OAI2Exception('noSetHierarchy')
|
|
||||||
if ($count) {
|
if ($count) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if ($set != '') {
|
||||||
|
throw new OAI2Exception('noSetHierarchy');
|
||||||
|
}
|
||||||
|
if ($metadataPrefix != 'oai_dc') {
|
||||||
|
throw new OAI2Exception('noRecordsMatch');
|
||||||
|
}
|
||||||
return array($example_record);
|
return array($example_record);
|
||||||
},
|
},
|
||||||
|
|
||||||
'GetRecord' =>
|
'GetRecord' =>
|
||||||
function($identifier, $metadataPrefix) use ($example_record) {
|
function($identifier, $metadataPrefix) use ($example_record) {
|
||||||
if ($identifier != 'a.b.c') {
|
if ($identifier != 'a.b.c') {
|
||||||
throw new OAI2Exception('idDoesNotExist', '', $identifier);
|
throw new OAI2Exception('idDoesNotExist');
|
||||||
}
|
}
|
||||||
return $example_record;
|
return $example_record;
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,61 +2,33 @@
|
||||||
|
|
||||||
class OAI2Exception extends Exception {
|
class OAI2Exception extends Exception {
|
||||||
|
|
||||||
function __construct($code = 0, $argument = '', $value = '') {
|
function __construct($code) {
|
||||||
|
|
||||||
$this->errorTable = array(
|
$this->errorTable = array(
|
||||||
'badArgument' => array(
|
'badArgument' => array(
|
||||||
'text' => "Attribute '{$argument}' is not allowed to appear in element 'request'.",
|
'text' => "The request includes illegal arguments, is missing required arguments, includes a repeated argument, or values for arguments have an illegal syntax.",
|
||||||
),
|
),
|
||||||
'badResumptionToken' => array(
|
'badResumptionToken' => array(
|
||||||
'text' => "The resumptionToken '{$value}' does not exist or has already expired.",
|
'text' => "The value of the resumptionToken argument is invalid or expired",
|
||||||
),
|
|
||||||
'badGranularity' => array(
|
|
||||||
'text' => "The value '{$value}' of attribute '{$argument}' on element 'request' is not valid with respect to its type, 'UTCdatetimeType'.",
|
|
||||||
'code' => 'badArgument',
|
|
||||||
),
|
),
|
||||||
'badVerb' => array(
|
'badVerb' => array(
|
||||||
'text' => "Illegal OAI verb",
|
'text' => "Value of the verb argument is not a legal OAI-PMH verb, the verb argument is missing, or the verb argument is repeated.",
|
||||||
),
|
),
|
||||||
'cannotDisseminateFormat' => array(
|
'cannotDisseminateFormat' => array(
|
||||||
'text' => "The metadata format '{$value}' given by {$argument} is not supported by this repository.",
|
'text' => "The metadata format identified by the value given for the metadataPrefix argument is not supported by the item or by the repository.",
|
||||||
),
|
|
||||||
'exclusiveArgument' => array(
|
|
||||||
'text' => 'The usage of resumptionToken as an argument allows no other arguments.',
|
|
||||||
'code' => 'badArgument',
|
|
||||||
),
|
),
|
||||||
'idDoesNotExist' => array(
|
'idDoesNotExist' => array(
|
||||||
'text' => "The value '{$value}' of the identifier does not exist in this repository.",
|
'text' => "The value of the identifier argument is unknown or illegal in this repository.",
|
||||||
),
|
|
||||||
'missingArgument' => array(
|
|
||||||
'text' => "The required argument '{$argument}' is missing in the request.",
|
|
||||||
'code' => 'badArgument',
|
|
||||||
),
|
),
|
||||||
'noRecordsMatch' => array(
|
'noRecordsMatch' => array(
|
||||||
'text' => 'The combination of the given values results in an empty list.',
|
'text' => 'The combination of the values of the from, until, set and metadataPrefix arguments results in an empty list.',
|
||||||
),
|
),
|
||||||
'noMetadataFormats' => array(
|
'noMetadataFormats' => array(
|
||||||
'text' => 'There are no metadata formats available for the specified item.',
|
'text' => 'There are no metadata formats available for the specified item.',
|
||||||
),
|
),
|
||||||
'noSetHierarchy' => array(
|
'noSetHierarchy' => array(
|
||||||
'text' => 'This repository does not support sets.',
|
'text' => 'The repository does not support sets.',
|
||||||
),
|
),
|
||||||
'sameArgument' => array(
|
|
||||||
'text' => 'Do not use the same argument more than once.',
|
|
||||||
'code' => 'badArgument',
|
|
||||||
),
|
|
||||||
'sameVerb' => array(
|
|
||||||
'text' => 'Do not use verb more than once.',
|
|
||||||
'code' => 'badVerb',
|
|
||||||
),
|
|
||||||
'notImp' => array(
|
|
||||||
'text' => 'Not yet implemented.',
|
|
||||||
'code' => 'debug',
|
|
||||||
),
|
|
||||||
''=> array(
|
|
||||||
'text' => "Unknown error: code: '{'code'}', argument: '{$argument}', value: '{$value}'",
|
|
||||||
'code' => 'badArgument',
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
parent::__construct($this->errorTable[$code]['text']);
|
parent::__construct($this->errorTable[$code]['text']);
|
||||||
$this->code = $code;
|
$this->code = $code;
|
||||||
|
|
|
@ -42,7 +42,7 @@ class OAI2Server {
|
||||||
call_user_func(array($this, $this->verb));
|
call_user_func(array($this, $this->verb));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->errors[] = new OAI2Exception('badVerb', $args['verb']);
|
$this->errors[] = new OAI2Exception('badVerb');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ class OAI2Server {
|
||||||
|
|
||||||
if (count($this->args) > 0) {
|
if (count($this->args) > 0) {
|
||||||
foreach($this->args as $key => $val) {
|
foreach($this->args as $key => $val) {
|
||||||
$this->errors[] = new OAI2Exception('badArgument', $key, $val);
|
$this->errors[] = new OAI2Exception('badArgument');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach($this->identifyResponse as $key => $val) {
|
foreach($this->identifyResponse as $key => $val) {
|
||||||
|
@ -79,7 +79,7 @@ class OAI2Server {
|
||||||
|
|
||||||
foreach ($this->args as $argument => $value) {
|
foreach ($this->args as $argument => $value) {
|
||||||
if ($argument != 'identifier') {
|
if ($argument != 'identifier') {
|
||||||
$this->errors[] = new OAI2Exception('badArgument', $argument, $value);
|
$this->errors[] = new OAI2Exception('badArgument');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($this->args['identifier'])) {
|
if (isset($this->args['identifier'])) {
|
||||||
|
@ -109,7 +109,7 @@ class OAI2Server {
|
||||||
|
|
||||||
if (isset($this->args['resumptionToken'])) {
|
if (isset($this->args['resumptionToken'])) {
|
||||||
if (count($this->args) > 1) {
|
if (count($this->args) > 1) {
|
||||||
$this->errors[] = new OAI2Exception('exclusiveArgument');
|
$this->errors[] = new OAI2Exception('badArgument');
|
||||||
} else {
|
} else {
|
||||||
if ((int)$val+$this->token_valid < time()) {
|
if ((int)$val+$this->token_valid < time()) {
|
||||||
$this->errors[] = new OAI2Exception('badResumptionToken');
|
$this->errors[] = new OAI2Exception('badResumptionToken');
|
||||||
|
@ -146,15 +146,15 @@ class OAI2Server {
|
||||||
public function GetRecord() {
|
public function GetRecord() {
|
||||||
|
|
||||||
if (!isset($this->args['metadataPrefix'])) {
|
if (!isset($this->args['metadataPrefix'])) {
|
||||||
$this->errors[] = new OAI2Exception('missingArgument', 'metadataPrefix');
|
$this->errors[] = new OAI2Exception('badArgument');
|
||||||
} else {
|
} else {
|
||||||
$metadataFormats = call_user_func($this->listMetadataFormatsCallback);
|
$metadataFormats = call_user_func($this->listMetadataFormatsCallback);
|
||||||
if (!isset($metadataFormats[$this->args['metadataPrefix']])) {
|
if (!isset($metadataFormats[$this->args['metadataPrefix']])) {
|
||||||
$this->errors[] = new OAI2Exception('cannotDisseminateFormat', 'metadataPrefix', $this->args['metadataPrefix']);
|
$this->errors[] = new OAI2Exception('cannotDisseminateFormat');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isset($this->args['identifier'])) {
|
if (!isset($this->args['identifier'])) {
|
||||||
$this->errors[] = new OAI2Exception('missingArgument', 'identifier');
|
$this->errors[] = new OAI2Exception('badArgument');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($this->errors)) {
|
if (empty($this->errors)) {
|
||||||
|
@ -179,7 +179,7 @@ class OAI2Server {
|
||||||
$this->add_metadata($cur_record, $record);
|
$this->add_metadata($cur_record, $record);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->errors[] = new OAI2Exception('idDoesNotExist', 'identifier', $identifier);
|
$this->errors[] = new OAI2Exception('idDoesNotExist');
|
||||||
}
|
}
|
||||||
} catch (OAI2Exception $e) {
|
} catch (OAI2Exception $e) {
|
||||||
$this->errors[] = $e;
|
$this->errors[] = $e;
|
||||||
|
@ -202,39 +202,39 @@ class OAI2Server {
|
||||||
|
|
||||||
if (isset($this->args['resumptionToken'])) {
|
if (isset($this->args['resumptionToken'])) {
|
||||||
if (count($this->args) > 1) {
|
if (count($this->args) > 1) {
|
||||||
$this->errors[] = new OAI2Exception('exclusiveArgument');
|
$this->errors[] = new OAI2Exception('badArgument');
|
||||||
} else {
|
} else {
|
||||||
if ((int)$val+$this->token_valid < time()) {
|
if ((int)$val+$this->token_valid < time()) {
|
||||||
$this->errors[] = new OAI2Exception('badResumptionToken');
|
$this->errors[] = new OAI2Exception('badResumptionToken');
|
||||||
} else {
|
} else {
|
||||||
if (!file_exists($this->token_prefix.$this->args['resumptionToken'])) {
|
if (!file_exists($this->token_prefix.$this->args['resumptionToken'])) {
|
||||||
$this->errors[] = new OAI2Exception('badResumptionToken', '', $this->args['resumptionToken']);
|
$this->errors[] = new OAI2Exception('badResumptionToken');
|
||||||
} else {
|
} else {
|
||||||
if ($readings = $this->readResumptionToken($this->token_prefix.$this->args['resumptionToken'])) {
|
if ($readings = $this->readResumptionToken($this->token_prefix.$this->args['resumptionToken'])) {
|
||||||
list($deliveredRecords, $metadataPrefix, $from, $until, $set) = $readings;
|
list($deliveredRecords, $metadataPrefix, $from, $until, $set) = $readings;
|
||||||
} else {
|
} else {
|
||||||
$this->errors[] = new OAI2Exception('badResumptionToken', '', $this->args['resumptionToken']);
|
$this->errors[] = new OAI2Exception('badResumptionToken');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!isset($this->args['metadataPrefix'])) {
|
if (!isset($this->args['metadataPrefix'])) {
|
||||||
$this->errors[] = new OAI2Exception('missingArgument', 'metadataPrefix');
|
$this->errors[] = new OAI2Exception('badArgument');
|
||||||
} else {
|
} else {
|
||||||
$metadataFormats = call_user_func($this->listMetadataFormatsCallback);
|
$metadataFormats = call_user_func($this->listMetadataFormatsCallback);
|
||||||
if (!isset($metadataFormats[$this->args['metadataPrefix']])) {
|
if (!isset($metadataFormats[$this->args['metadataPrefix']])) {
|
||||||
$this->errors[] = new OAI2Exception('cannotDisseminateFormat', 'metadataPrefix', $this->args['metadataPrefix']);
|
$this->errors[] = new OAI2Exception('cannotDisseminateFormat');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($this->args['from'])) {
|
if (isset($this->args['from'])) {
|
||||||
if(!$this->checkDateFormat($this->args['from'])) {
|
if(!$this->checkDateFormat($this->args['from'])) {
|
||||||
$this->errors[] = new OAI2Exception('badGranularity', 'from', $this->args['from']);
|
$this->errors[] = new OAI2Exception('badArgument');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($this->args['until'])) {
|
if (isset($this->args['until'])) {
|
||||||
if(!$this->checkDateFormat($this->args['until'])) {
|
if(!$this->checkDateFormat($this->args['until'])) {
|
||||||
$this->errors[] = new OAI2Exception('badGranularity', 'until', $this->args['until']);
|
$this->errors[] = new OAI2Exception('badArgument');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue