You are here

final class Lock in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/TempStore/Lock.php \Drupal\Core\TempStore\Lock

Provides a value object representing the lock from a TempStore.

Hierarchy

  • class \Drupal\Core\TempStore\Lock

Expanded class hierarchy of Lock

4 files declare their use of Lock
PrivateTempStoreTest.php in core/tests/Drupal/Tests/Core/TempStore/PrivateTempStoreTest.php
SharedTempStoreTest.php in core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php
ViewUI.php in core/modules/views_ui/src/ViewUI.php
ViewUIObjectTest.php in core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php
1 string reference to 'Lock'
LockFunctionalTest::testLockAcquire in core/modules/system/tests/src/Functional/Lock/LockFunctionalTest.php
Confirms that we can acquire and release locks in two parallel requests.

File

core/lib/Drupal/Core/TempStore/Lock.php, line 8

Namespace

Drupal\Core\TempStore
View source
final class Lock {

  /**
   * The owner ID.
   *
   * @var int
   */
  private $ownerId;

  /**
   * The timestamp the lock was last updated.
   *
   * @var int
   */
  private $updated;

  /**
   * Constructs a new Lock object.
   *
   * @param int $owner_id
   *   The owner ID.
   * @param int $updated
   *   The updated timestamp.
   */
  public function __construct($owner_id, $updated) {
    $this->ownerId = $owner_id;
    $this->updated = $updated;
  }

  /**
   * Gets the owner ID.
   *
   * @return int
   *   The owner ID.
   */
  public function getOwnerId() {
    return $this->ownerId;
  }

  /**
   * Gets the timestamp of the last update to the lock.
   *
   * @return int
   *   The updated timestamp.
   */
  public function getUpdated() {
    return $this->updated;
  }

  /**
   * Provides backwards compatibility for using the lock as a \stdClass object.
   */
  public function __get($name) {
    if ($name === 'owner') {
      @trigger_error('Using the "owner" public property of a TempStore lock is deprecated in Drupal 8.7.0 and will not be allowed in Drupal 9.0.0. Use \\Drupal\\Core\\TempStore\\Lock::getOwnerId() instead. See https://www.drupal.org/node/3025869.', E_USER_DEPRECATED);
      return $this
        ->getOwnerId();
    }
    if ($name === 'updated') {
      @trigger_error('Using the "updated" public property of a TempStore lock is deprecated in Drupal 8.7.0 and will not be allowed in Drupal 9.0.0. Use \\Drupal\\Core\\TempStore\\Lock::getUpdated() instead. See https://www.drupal.org/node/3025869.', E_USER_DEPRECATED);
      return $this
        ->getUpdated();
    }
    throw new \InvalidArgumentException($name);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Lock::$ownerId private property The owner ID.
Lock::$updated private property The timestamp the lock was last updated.
Lock::getOwnerId public function Gets the owner ID.
Lock::getUpdated public function Gets the timestamp of the last update to the lock.
Lock::__construct public function Constructs a new Lock object.
Lock::__get public function Provides backwards compatibility for using the lock as a \stdClass object.