Skip to content

Commit

Permalink
Add fallback to $_SERVER (closes #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
enumag committed Feb 8, 2018
1 parent ec4809f commit 412f139
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/RequestTimeAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function __construct(RequestStack $requestStack)

public function getRequestTime(): DateTimeImmutable
{
$time = $this->requestStack->getCurrentRequest()->server->get('REQUEST_TIME_FLOAT');
$request = $this->requestStack->getCurrentRequest();
$time = $request ? $request->server->get('REQUEST_TIME_FLOAT') : $_SERVER['REQUEST_TIME_FLOAT'];
return (new DateTimeImmutable(sprintf('@%.6f', $time)))->setTimezone(new DateTimeZone(date_default_timezone_get()));
}

Expand Down

0 comments on commit 412f139

Please sign in to comment.