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,8 +24,7 @@ namespace OCC\OAI2;
class Exception extends \Exception {
public function __construct($code) {
$this->errorTable = [
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.',
],
@ -49,8 +48,10 @@ class Exception extends \Exception {
],
'noSetHierarchy' => [
'text' => 'The repository does not support sets.',
],
]
];
public function __construct($code) {
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);
}
}