function Time::getRequestTime

Same name in other branches
  1. 9 core/lib/Drupal/Component/Datetime/Time.php \Drupal\Component\Datetime\Time::getRequestTime()
  2. 10 core/lib/Drupal/Component/Datetime/Time.php \Drupal\Component\Datetime\Time::getRequestTime()
  3. 11.x core/lib/Drupal/Component/Datetime/Time.php \Drupal\Component\Datetime\Time::getRequestTime()

Overrides TimeInterface::getRequestTime

1 call to Time::getRequestTime()
TestTime::getRequestTime in core/modules/update/tests/modules/update_test/src/Datetime/TestTime.php
Returns the timestamp for the current request.
1 method overrides Time::getRequestTime()
TestTime::getRequestTime in core/modules/update/tests/modules/update_test/src/Datetime/TestTime.php
Returns the timestamp for the current request.

File

core/lib/Drupal/Component/Datetime/Time.php, line 32

Class

Time
Provides a class for obtaining system time.

Namespace

Drupal\Component\Datetime

Code

public function getRequestTime() {
    $request = $this->requestStack
        ->getCurrentRequest();
    if ($request) {
        return $request->server
            ->get('REQUEST_TIME');
    }
    // If this is called prior to the request being pushed to the stack fallback
    // to built-in globals (if available) or the system time.
    return $_SERVER['REQUEST_TIME'] ?? $this->getCurrentTime();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.