Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Refactor expiry dates to intervals #1500

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions src/Passport.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,50 @@ class Passport
* The date when access tokens expire.
*
* @var \DateTimeInterface|null
*
* @deprecated Will be removed in the next major Passport release.
*/
public static $tokensExpireAt;

/**
* The interval when access tokens expire.
*
* @var \DateInterval|null
*/
public static $tokensExpireIn;

/**
* The date when refresh tokens expire.
*
* @var \DateTimeInterface|null
*
* @deprecated Will be removed in the next major Passport release.
*/
public static $refreshTokensExpireAt;

/**
* The date when refresh tokens expire.
*
* @var \DateInterval|null
*/
public static $refreshTokensExpireIn;

/**
* The date when personal access tokens expire.
*
* @var \DateTimeInterface|null
*
* @deprecated Will be removed in the next major Passport release.
*/
public static $personalAccessTokensExpireAt;

/**
* The date when personal access tokens expire.
*
* @var \DateInterval|null
*/
public static $personalAccessTokensExpireIn;

/**
* The name for API token cookies.
*
Expand Down Expand Up @@ -261,12 +288,11 @@ public static function tokensCan(array $scopes)
public static function tokensExpireIn(DateTimeInterface $date = null)
{
if (is_null($date)) {
return static::$tokensExpireAt
? Carbon::now()->diff(static::$tokensExpireAt)
: new DateInterval('P1Y');
return static::$tokensExpireIn ?? new DateInterval('P1Y');
}

static::$tokensExpireAt = $date;
static::$tokensExpireIn = Carbon::now()->diff($date);

return new static;
}
Expand All @@ -280,12 +306,11 @@ public static function tokensExpireIn(DateTimeInterface $date = null)
public static function refreshTokensExpireIn(DateTimeInterface $date = null)
{
if (is_null($date)) {
return static::$refreshTokensExpireAt
? Carbon::now()->diff(static::$refreshTokensExpireAt)
: new DateInterval('P1Y');
return static::$refreshTokensExpireIn ?? new DateInterval('P1Y');
}

static::$refreshTokensExpireAt = $date;
static::$refreshTokensExpireIn = Carbon::now()->diff($date);

return new static;
}
Expand All @@ -299,12 +324,11 @@ public static function refreshTokensExpireIn(DateTimeInterface $date = null)
public static function personalAccessTokensExpireIn(DateTimeInterface $date = null)
{
if (is_null($date)) {
return static::$personalAccessTokensExpireAt
? Carbon::now()->diff(static::$personalAccessTokensExpireAt)
: new DateInterval('P1Y');
return static::$personalAccessTokensExpireIn ?? new DateInterval('P1Y');
}

static::$personalAccessTokensExpireAt = $date;
static::$personalAccessTokensExpireIn = Carbon::now()->diff($date);

return new static;
}
Expand Down