You are here

class TimeChanger in Content locking (anti-concurrent editing) 8

Same name and namespace in other branches
  1. 8.2 modules/content_lock_timeout/tests/modules/content_lock_timeout_test/src/TimeChanger.php \Drupal\content_lock_timeout_test\TimeChanger

This is a datetime.time service for testing only.

@package Drupal\Tests\content_lock_timeout\Functional

Hierarchy

Expanded class hierarchy of TimeChanger

File

modules/content_lock_timeout/tests/modules/content_lock_timeout_test/src/TimeChanger.php, line 12

Namespace

Drupal\content_lock_timeout_test
View source
class TimeChanger extends Time {
  protected $overwrittenTime = NULL;

  /**
   * {@inheritdoc}
   */
  public function getCurrentTime() {
    $time = \Drupal::keyValue('time')
      ->get('time', NULL);
    if (!empty($time)) {
      return $time;
    }
    return parent::getCurrentTime();
  }

  /**
   * Forward current time to the given timestamp.
   *
   * @param int $time
   *   New time to set.
   */
  public function setCurrentTime($time) {
    \Drupal::keyValue('time')
      ->set('time', $time);
  }

  /**
   * Reset the current time to the real time.
   */
  public function resetCurrentTime() {
    \Drupal::keyValue('time')
      ->delete('time');
  }

  /**
   * {@inheritdoc}
   */
  public function getRequestTime() {
    $time = \Drupal::keyValue('time')
      ->get('time', NULL);
    if (!empty($time)) {
      return $time;
    }
    return parent::getRequestTime();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Time::$requestStack protected property The request stack.
Time::getCurrentMicroTime public function Returns the current system time with microsecond precision. Overrides TimeInterface::getCurrentMicroTime
Time::getRequestMicroTime public function Returns the timestamp for the current request with microsecond precision. Overrides TimeInterface::getRequestMicroTime
Time::__construct public function Constructs a Time object.
TimeChanger::$overwrittenTime protected property
TimeChanger::getCurrentTime public function Returns the current system time as an integer. Overrides Time::getCurrentTime
TimeChanger::getRequestTime public function Returns the timestamp for the current request. Overrides Time::getRequestTime
TimeChanger::resetCurrentTime public function Reset the current time to the real time.
TimeChanger::setCurrentTime public function Forward current time to the given timestamp.