fix: Remove deprecated RFC7231 constant to avoid warnings on PHP 8.5

Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
This commit is contained in:
David Dreschner 2026-02-09 16:26:04 +01:00 committed by Daniel Kesselberg
parent 201a97a4ed
commit 2bb9524c84
No known key found for this signature in database
GPG key ID: 4A81C29F63464E8F
5 changed files with 19 additions and 7 deletions

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace OCA\DAV\Provisioning\Apple;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Constants;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\INode;
use Sabre\DAV\IProperties;
@ -60,7 +61,7 @@ class AppleProvisioningNode implements INode, IProperties {
return [
'{DAV:}getcontentlength' => 42,
'{DAV:}getlastmodified' => $datetime->format(\DateTimeInterface::RFC7231),
'{DAV:}getlastmodified' => $datetime->format(Constants::DATE_RFC7231),
];
}

View file

@ -11,6 +11,7 @@ namespace OC\AppFramework\Middleware;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Middleware;
use OCP\Constants;
use OCP\IRequest;
class NotModifiedMiddleware extends Middleware {
@ -27,7 +28,7 @@ class NotModifiedMiddleware extends Middleware {
}
$modifiedSinceHeader = $this->request->getHeader('IF_MODIFIED_SINCE');
if ($modifiedSinceHeader !== '' && $response->getLastModified() !== null && trim($modifiedSinceHeader) === $response->getLastModified()->format(\DateTimeInterface::RFC7231)) {
if ($modifiedSinceHeader !== '' && $response->getLastModified() !== null && trim($modifiedSinceHeader) === $response->getLastModified()->format(Constants::DATE_RFC7231)) {
$response->setStatus(Http::STATUS_NOT_MODIFIED);
return $response;
}

View file

@ -9,6 +9,7 @@ namespace OCP\AppFramework\Http;
use OCP\AppFramework\Http;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Constants;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserSession;
@ -98,7 +99,7 @@ class Response {
$time = \OCP\Server::get(ITimeFactory::class);
$expires->setTimestamp($time->getTime());
$expires->add(new \DateInterval('PT' . $cacheSeconds . 'S'));
$this->addHeader('Expires', $expires->format(\DateTimeInterface::RFC7231));
$this->addHeader('Expires', $expires->format(Constants::DATE_RFC7231));
} else {
$this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
unset($this->headers['Expires']);
@ -240,7 +241,7 @@ class Response {
];
if ($this->lastModified) {
$mergeWith['Last-Modified'] = $this->lastModified->format(\DateTimeInterface::RFC7231);
$mergeWith['Last-Modified'] = $this->lastModified->format(Constants::DATE_RFC7231);
}
if ($this->ETag) {

View file

@ -59,4 +59,12 @@ class Constants {
* cf. sharing.maxAutocompleteResults in config.sample.php.
*/
public const SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT = 25;
/**
* Replacement for the built-in `DATE_RFC7231` constant
* deprecated since PHP 8.5.
*
* @since 34.0.0
*/
public const DATE_RFC7231 = 'D, d M Y H:i:s \G\M\T';
}

View file

@ -12,6 +12,7 @@ use OC\AppFramework\Middleware\NotModifiedMiddleware;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Response;
use OCP\Constants;
use OCP\IRequest;
class NotModifiedMiddlewareTest extends \Test\TestCase {
@ -44,13 +45,13 @@ class NotModifiedMiddlewareTest extends \Test\TestCase {
[null, '"etag"', null, '', false],
['etag', '"etag"', null, '', true],
[null, '', $now, $now->format(\DateTimeInterface::RFC7231), true],
[null, '', $now, $now->format(Constants::DATE_RFC7231), true],
[null, '', $now, $now->format(\DateTimeInterface::ATOM), false],
[null, '', null, $now->format(\DateTimeInterface::RFC7231), false],
[null, '', null, $now->format(Constants::DATE_RFC7231), false],
[null, '', $now, '', false],
['etag', '"etag"', $now, $now->format(\DateTimeInterface::ATOM), true],
['etag', '"etag"', $now, $now->format(\DateTimeInterface::RFC7231), true],
['etag', '"etag"', $now, $now->format(Constants::DATE_RFC7231), true],
];
}