From beeef31d9123528833ebe695ac720c1d24d7dcd1 Mon Sep 17 00:00:00 2001 From: Sebastian Meyer Date: Wed, 8 May 2024 15:29:58 +0200 Subject: [PATCH] Fix deprecation warnings for PHP 8.1 --- Classes/Exception.php | 53 ++++++++++++++++++++++--------------------- Classes/Response.php | 6 ++++- Classes/Server.php | 14 ++++++++---- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/Classes/Exception.php b/Classes/Exception.php index c4d5b58..5d0d1a2 100644 --- a/Classes/Exception.php +++ b/Classes/Exception.php @@ -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; } diff --git a/Classes/Response.php b/Classes/Response.php index d2d3c1f..17d1dfd 100644 --- a/Classes/Response.php +++ b/Classes/Response.php @@ -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) == '/') { diff --git a/Classes/Server.php b/Classes/Server.php index 0daf4c6..2a5eada 100644 --- a/Classes/Server.php +++ b/Classes/Server.php @@ -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); } }