Skip to content

Commit

Permalink
Refactor expiry dates to intervals (#1500)
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints authored Oct 28, 2021
1 parent 25fa27e commit fda2c2e
Showing 1 changed file with 33 additions and 9 deletions.
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

0 comments on commit fda2c2e

Please sign in to comment.