Skip to content

Commit 8ce19ad

Browse files
committed
Remove deprecated constants from RFC7231 for date formats
1 parent a45dd9f commit 8ce19ad

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

src/Cookie.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace Framework\HTTP;
1111

1212
use DateTime;
13-
use DateTimeInterface;
1413
use DateTimeZone;
1514
use Exception;
1615
use InvalidArgumentException;
@@ -64,7 +63,7 @@ public function toString() : string
6463
$string = $this->getName() . '=' . $this->getValue();
6564
$part = $this->getExpires();
6665
if ($part !== null) {
67-
$string .= '; expires=' . $this->expires->format(DateTimeInterface::RFC7231);
66+
$string .= '; expires=' . $this->expires->format('D, d M Y H:i:s \G\M\T');
6867
$string .= '; Max-Age=' . $this->expires->diff(new DateTime('-1 second'))->s;
6968
}
7069
$part = $this->getPath();

src/Response.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace Framework\HTTP;
1111

1212
use DateTime;
13-
use DateTimeInterface;
1413
use DateTimeZone;
1514
use Framework\HTTP\Debug\HTTPCollector;
1615
use InvalidArgumentException;
@@ -857,7 +856,7 @@ public function setDate(DateTime $datetime = new DateTime()) : static
857856
$date->setTimezone(new DateTimeZone('UTC'));
858857
$this->setHeader(
859858
ResponseHeader::DATE,
860-
$date->format(DateTimeInterface::RFC7231)
859+
$date->format('D, d M Y H:i:s \G\M\T')
861860
);
862861
return $this;
863862
}
@@ -897,7 +896,7 @@ public function setExpires(DateTime $datetime = new DateTime()) : static
897896
$date->setTimezone(new DateTimeZone('UTC'));
898897
$this->setHeader(
899898
ResponseHeader::EXPIRES,
900-
$date->format(DateTimeInterface::RFC7231)
899+
$date->format('D, d M Y H:i:s \G\M\T')
901900
);
902901
return $this;
903902
}
@@ -917,7 +916,7 @@ public function setLastModified(DateTime $datetime = new DateTime()) : static
917916
$date->setTimezone(new DateTimeZone('UTC'));
918917
$this->setHeader(
919918
ResponseHeader::LAST_MODIFIED,
920-
$date->format(DateTimeInterface::RFC7231)
919+
$date->format('D, d M Y H:i:s \G\M\T')
921920
);
922921
return $this;
923922
}

src/ResponseDownload.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ public function setDownload(
8686
"Could not get the file modification time of '{$this->filepath}'"
8787
);
8888
}
89-
$this->setHeader(ResponseHeader::LAST_MODIFIED, \gmdate(\DATE_RFC7231, $filemtime));
89+
$this->setHeader(
90+
ResponseHeader::LAST_MODIFIED,
91+
\gmdate('D, d M Y H:i:s \G\M\T', $filemtime)
92+
);
9093
$filename ??= \basename($filepath);
9194
$filename = \htmlspecialchars($filename, \ENT_QUOTES | \ENT_HTML5);
9295
$filename = \strtr($filename, ['/' => '_', '\\' => '_']);

tests/ResponseTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ public function testToString() : void
539539
{
540540
$startLine = 'HTTP/1.1 200 OK';
541541
$headerLines = [
542-
'Date: ' . \gmdate(\DATE_RFC7231),
542+
'Date: ' . \gmdate('D, d M Y H:i:s \G\M\T'),
543543
'Content-Type: text/html; charset=UTF-8',
544544
];
545545
$body = <<<'HTML'
@@ -565,7 +565,7 @@ public function testToStringWithoutBodyAndContentType() : void
565565
{
566566
$startLine = 'HTTP/1.1 200 OK';
567567
$headerLines = [
568-
'Date: ' . \gmdate(\DATE_RFC7231),
568+
'Date: ' . \gmdate('D, d M Y H:i:s \G\M\T'),
569569
];
570570
$message = $startLine . "\r\n"
571571
. \implode("\r\n", $headerLines) . "\r\n"
@@ -580,12 +580,12 @@ public function testToStringWithDownload() : void
580580
$length = \strlen($body);
581581
$startLine = 'HTTP/1.1 200 OK';
582582
$headerLines = [
583-
'Last-Modified: ' . \gmdate(\DATE_RFC7231, (int) \filemtime($filename)),
583+
'Last-Modified: ' . \gmdate('D, d M Y H:i:s \G\M\T', (int) \filemtime($filename)),
584584
'Content-Disposition: attachment; filename="file.txt"',
585585
'Accept-Ranges: bytes',
586586
'Content-Length: ' . $length,
587587
'Content-Type: text/plain',
588-
'Date: ' . \gmdate(\DATE_RFC7231),
588+
'Date: ' . \gmdate('D, d M Y H:i:s \G\M\T'),
589589
];
590590
$this->response->setDownload($filename);
591591
$message = $startLine . "\r\n"
@@ -617,12 +617,12 @@ public function testToStringWithDownloadMultipart() : void
617617
$length = \strlen($body);
618618
$startLine = 'HTTP/1.1 206 Partial Content';
619619
$headerLines = [
620-
'Last-Modified: ' . \gmdate(\DATE_RFC7231, (int) \filemtime($filename)),
620+
'Last-Modified: ' . \gmdate('D, d M Y H:i:s \G\M\T', (int) \filemtime($filename)),
621621
'Content-Disposition: attachment; filename="fo_o.b&quot;ar"',
622622
'Accept-Ranges: bytes',
623623
'Content-Length: ' . $length,
624624
'Content-Type: multipart/x-byteranges; boundary=' . $boundary,
625-
'Date: ' . \gmdate(\DATE_RFC7231),
625+
'Date: ' . \gmdate('D, d M Y H:i:s \G\M\T'),
626626
];
627627
$this->response->setDownload($filename, filename: 'fo/o.b"ar');
628628
$message = $startLine . "\r\n"

0 commit comments

Comments
 (0)