Fix deprecation warnings for PHP 8.1

This commit is contained in:
Sebastian Meyer 2024-05-08 15:29:58 +02:00
parent 53670681b1
commit beeef31d91
3 changed files with 42 additions and 31 deletions

View File

@ -24,33 +24,34 @@ namespace OCC\OAI2;
class Exception extends \Exception {
private array $errorTable = [
'badArgument' => [
'text' => 'The request includes illegal arguments, is missing required arguments, includes a repeated argument, or values for arguments have an illegal syntax.',
],
'badResumptionToken' => [
'text' => 'The value of the resumptionToken argument is invalid or expired.',
],
'badVerb' => [
'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' => [
'text' => 'The metadata format identified by the value given for the metadataPrefix argument is not supported by the item or by the repository.',
],
'idDoesNotExist' => [
'text' => 'The value of the identifier argument is unknown or illegal in this repository.',
],
'noRecordsMatch' => [
'text' => 'The combination of the values of the from, until, set and metadataPrefix arguments results in an empty list.',
],
'noMetadataFormats' => [
'text' => 'There are no metadata formats available for the specified item.',
],
'noSetHierarchy' => [
'text' => 'The repository does not support sets.',
]
];
public function __construct($code) {
$this->errorTable = [
'badArgument' => [
'text' => 'The request includes illegal arguments, is missing required arguments, includes a repeated argument, or values for arguments have an illegal syntax.',
],
'badResumptionToken' => [
'text' => 'The value of the resumptionToken argument is invalid or expired.',
],
'badVerb' => [
'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' => [
'text' => 'The metadata format identified by the value given for the metadataPrefix argument is not supported by the item or by the repository.',
],
'idDoesNotExist' => [
'text' => 'The value of the identifier argument is unknown or illegal in this repository.',
],
'noRecordsMatch' => [
'text' => 'The combination of the values of the from, until, set and metadataPrefix arguments results in an empty list.',
],
'noMetadataFormats' => [
'text' => 'There are no metadata formats available for the specified item.',
],
'noSetHierarchy' => [
'text' => 'The repository does not support sets.',
],
];
parent::__construct($this->errorTable[$code]['text']);
$this->code = $code;
}

View File

@ -24,7 +24,11 @@ namespace OCC\OAI2;
class Response {
public $doc; // DOMDocument. Handle of current XML Document object
public \DOMDocument $doc; // DOMDocument. Handle of current XML Document object
private string $verb = '';
private \DOMElement $verbNode;
public function __construct($uri, $verb, $request_args) {
if (substr($uri, -1, 1) == '/') {

View File

@ -34,6 +34,12 @@ class Server {
private $max_records = 100;
private $token_prefix = '/tmp/oai2-';
private $token_valid = 86400;
private $uri = '';
private $identifyResponse;
private $listMetadataFormatsCallback;
private $listRecordsCallback;
private $getRecordCallback;
private Response $response;
public function __construct($uri, $args, $identifyResponse, $callbacks, $config) {
$this->uri = $uri;
@ -222,7 +228,7 @@ class Server {
if ($records_count - $deliveredRecords > $maxItems) {
$deliveredRecords += $maxItems;
$restoken = $this->createResumptionToken($deliveredRecords, $metadataPrefix, $from, $until);
$expirationDatetime = gmstrftime('%Y-%m-%dT%TZ', time()+$this->token_valid);
$expirationDatetime = date('Y-m-d\TH:i:s\Z', time()+$this->token_valid);
} elseif (isset($this->args['resumptionToken'])) {
// Last delivery, return empty resumptionToken
$restoken = null;
@ -277,8 +283,8 @@ class Server {
}
private function formatTimestamp($datestamp) {
if (is_array($time = strptime($datestamp, '%Y-%m-%dT%H:%M:%SZ')) || is_array($time = strptime($datestamp, '%Y-%m-%d'))) {
return gmmktime($time['tm_hour'], $time['tm_min'], $time['tm_sec'], $time['tm_mon'] + 1, $time['tm_mday'], $time['tm_year']+1900);
if (is_array($time = date_parse_from_format('Y-m-d\TH:i:s\Z', $datestamp)) || is_array($time = date_parse_from_format('Y-m-d\TH:i:s\Z', $datestamp))) {
return gmmktime($time['hour'], $time['minute'], $time['second'], $time['month'] + 1, $time['day'], $time['year']);
} else {
return null;
}
@ -289,7 +295,7 @@ class Server {
if ($datetime === false) {
$datetime = \DateTime::createFromFormat('Y-m-d', $date);
}
return ($datetime !== false) && ($datetime->getLastErrors() !== false);
return ($datetime !== false);
}
}