@@ -61,11 +61,8 @@ public function __construct(string $scopeName, string $region)
6161
6262 public function presign (Request $ request , Credentials $ credentials , RequestContext $ context ): void
6363 {
64- if (null === $ now = $ context ->getCurrentDate ()) {
65- $ now = new \DateTimeImmutable ();
66- } else {
67- $ now = new \DateTimeImmutable ($ now ->format (\DateTimeInterface::ATOM ));
68- }
64+ $ now = $ context ->getCurrentDate () ?? new \DateTimeImmutable ();
65+
6966 // Signer date have to be UTC https://docs.aws.amazon.com/general/latest/gr/sigv4-date-handling.html
7067 $ now = $ now ->setTimezone (new \DateTimeZone ('UTC ' ));
7168 $ expires = $ context ->getExpirationDate () ?? $ now ->add (new \DateInterval ('PT1H ' ));
@@ -75,11 +72,8 @@ public function presign(Request $request, Credentials $credentials, RequestConte
7572
7673 public function sign (Request $ request , Credentials $ credentials , RequestContext $ context ): void
7774 {
78- if (null === $ now = $ context ->getCurrentDate ()) {
79- $ now = new \DateTimeImmutable ();
80- } else {
81- $ now = new \DateTimeImmutable ($ now ->format (\DateTimeInterface::ATOM ));
82- }
75+ $ now = $ context ->getCurrentDate () ?? new \DateTimeImmutable ();
76+
8377 // Signer date have to be UTC https://docs.aws.amazon.com/general/latest/gr/sigv4-date-handling.html
8478 $ now = $ now ->setTimezone (new \DateTimeZone ('UTC ' ));
8579
@@ -106,7 +100,7 @@ protected function buildBodyDigest(Request $request, bool $isPresign): string
106100 return $ hash ;
107101 }
108102
109- private function handleSignature (Request $ request , Credentials $ credentials , \DateTimeInterface $ now , \DateTimeInterface $ expires , bool $ isPresign ): void
103+ private function handleSignature (Request $ request , Credentials $ credentials , \DateTimeImmutable $ now , \DateTimeImmutable $ expires , bool $ isPresign ): void
110104 {
111105 $ this ->removePresign ($ request );
112106 $ this ->sanitizeHostForHeader ($ request );
@@ -197,7 +191,7 @@ private function assignAmzQueryValues(Request $request, Credentials $credentials
197191 }
198192 }
199193
200- private function buildTime (Request $ request , \DateTimeInterface $ now , \DateTimeInterface $ expires , bool $ isPresign ): void
194+ private function buildTime (Request $ request , \DateTimeImmutable $ now , \DateTimeImmutable $ expires , bool $ isPresign ): void
201195 {
202196 if ($ isPresign ) {
203197 $ duration = $ expires ->getTimestamp () - $ now ->getTimestamp ();
@@ -215,7 +209,7 @@ private function buildTime(Request $request, \DateTimeInterface $now, \DateTimeI
215209 }
216210 }
217211
218- private function buildCredentialString (Request $ request , Credentials $ credentials , \DateTimeInterface $ now , bool $ isPresign ): array
212+ private function buildCredentialString (Request $ request , Credentials $ credentials , \DateTimeImmutable $ now , bool $ isPresign ): array
219213 {
220214 $ credentialScope = [$ now ->format ('Ymd ' ), $ this ->region , $ this ->scopeName , 'aws4_request ' ];
221215
@@ -259,7 +253,7 @@ private function convertBodyToQuery(Request $request): void
259253 $ request ->setBody (StringStream::create ('' ));
260254 }
261255
262- private function convertBodyToStream (Request $ request , \DateTimeInterface $ now , string $ credentialString , string $ signingKey , string &$ signature ): void
256+ private function convertBodyToStream (Request $ request , \DateTimeImmutable $ now , string $ credentialString , string $ signingKey , string &$ signature ): void
263257 {
264258 $ body = $ request ->getBody ();
265259 if ($ request ->hasHeader ('content-length ' )) {
@@ -388,7 +382,7 @@ private function buildCanonicalPath(Request $request): string
388382 return '/ ' . str_replace ('%2F ' , '/ ' , $ doubleEncoded );
389383 }
390384
391- private function buildStringToSign (\DateTimeInterface $ now , string $ credentialString , string $ canonicalRequest ): string
385+ private function buildStringToSign (\DateTimeImmutable $ now , string $ credentialString , string $ canonicalRequest ): string
392386 {
393387 return implode ("\n" , [
394388 self ::ALGORITHM_REQUEST ,
@@ -398,7 +392,7 @@ private function buildStringToSign(\DateTimeInterface $now, string $credentialSt
398392 ]);
399393 }
400394
401- private function buildChunkStringToSign (\DateTimeInterface $ now , string $ credentialString , string $ signature , string $ chunk ): string
395+ private function buildChunkStringToSign (\DateTimeImmutable $ now , string $ credentialString , string $ signature , string $ chunk ): string
402396 {
403397 static $ emptyHash ;
404398 $ emptyHash = $ emptyHash ?? hash ('sha256 ' , '' );
0 commit comments