Time.php in Drupal 10
File
core/lib/Drupal/Component/Datetime/Time.php
View source
<?php
namespace Drupal\Component\Datetime;
use Symfony\Component\HttpFoundation\RequestStack;
class Time implements TimeInterface {
protected $requestStack;
public function __construct(RequestStack $request_stack) {
$this->requestStack = $request_stack;
}
public function getRequestTime() {
$request = $this->requestStack
->getCurrentRequest();
if ($request) {
return $request->server
->get('REQUEST_TIME');
}
return $_SERVER['REQUEST_TIME'] ?? $this
->getCurrentTime();
}
public function getRequestMicroTime() {
$request = $this->requestStack
->getCurrentRequest();
if ($request) {
return $request->server
->get('REQUEST_TIME_FLOAT');
}
return $_SERVER['REQUEST_TIME_FLOAT'] ?? $this
->getCurrentMicroTime();
}
public function getCurrentTime() {
return time();
}
public function getCurrentMicroTime() {
return microtime(TRUE);
}
}
Classes
Name |
Description |
Time |
Provides a class for obtaining system time. |