Skip to content

Commit

Permalink
Merge pull request #45 from pauljosephkrogulec/feat/switch-DateTime-t…
Browse files Browse the repository at this point in the history
…o-DateTimeInterface

feat: switch DateTime to DateTimeInterface
  • Loading branch information
freekmurze authored Apr 5, 2023
2 parents 356b707 + 02f60b7 commit 5d95139
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/BaseUrlSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\UrlSigner;

use DateTime;
use DateTimeInterface;
use Spatie\UrlSigner\Exceptions\InvalidExpiration;
use Spatie\UrlSigner\Exceptions\InvalidSignatureKey;
use Spatie\UrlSigner\Support\Url;
Expand All @@ -27,7 +28,7 @@ abstract protected function createSignature(

public function sign(
string $url,
int|DateTime $expiration,
int|\DateTimeInterface $expiration,
string $signatureKey = null,
): string {
$signatureKey ??= $this->defaultSignatureKey;
Expand Down Expand Up @@ -95,13 +96,13 @@ protected function getIntendedUrl(string $url): string
]);
}

protected function getExpirationTimestamp(DateTime|int $expirationInSeconds): string
protected function getExpirationTimestamp(\DateTimeInterface|int $expirationInSeconds): string
{
if (is_int($expirationInSeconds)) {
$expirationInSeconds = (new DateTime())->modify($expirationInSeconds.' seconds');
}

if (! $expirationInSeconds instanceof DateTime) {
if (! $expirationInSeconds instanceof DateTimeInterface) {
throw InvalidExpiration::wrongType();
}

Expand Down
4 changes: 2 additions & 2 deletions src/UrlSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Spatie\UrlSigner;

use DateTime;
use DateTimeInterface;

interface UrlSigner
{
public function sign(
string $url,
int|DateTime $expiration,
int|\DateTimeInterface $expiration,
string $signatureKey = null
): string;

Expand Down

0 comments on commit 5d95139

Please sign in to comment.