Skip to content

Commit

Permalink
add support for using DateInterval as $expire
Browse files Browse the repository at this point in the history
  • Loading branch information
johanrosenson committed Feb 10, 2021
1 parent 67aac68 commit fe59baa
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/UtmParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,20 @@ public static function retrieve($request) : ?UtmParametersInterface
* Store the UTM parameters for later use
*
* @param mixed $response
* @param int|DateTimeInterface $expires
* @param int|DateInterval|DateTimeInterface $expires
* @return mixed
*/
public function remember($response, $expires)
{
if (\is_integer($expires)) {
Assert::greaterThan($expires, 0);
} elseif (! ($expires instanceof DateTimeInterface)) {
} elseif (! ($expires instanceof DateTimeInterface) && ! ($expires instanceof DateInterval)) {
throw new InvalidArgumentException('$expires argument must be an integer or an instanceof of DateTimeInterface');
}

$expires = $expires instanceof DateTimeInterface
? clone $expires
: (new DateTimeImmutable)->add(new DateInterval("P{$expires}D"));
: (new DateTimeImmutable)->add($expires instanceof DateInterval ? $expires : new DateInterval("P{$expires}D"));

if ($expires < (new DateTimeImmutable)) {
throw new InvalidArgumentException('$expires argument may not be in the past, use the forget() method to clear stored parameters');
Expand Down

0 comments on commit fe59baa

Please sign in to comment.