Lock.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Drupal\Core\TempStore;
  3. /**
  4. * Provides a value object representing the lock from a TempStore.
  5. */
  6. final class Lock {
  7. /**
  8. * The owner ID.
  9. *
  10. * @var int
  11. */
  12. private $ownerId;
  13. /**
  14. * The timestamp the lock was last updated.
  15. *
  16. * @var int
  17. */
  18. private $updated;
  19. /**
  20. * Constructs a new Lock object.
  21. *
  22. * @param int $owner_id
  23. * The owner ID.
  24. * @param int $updated
  25. * The updated timestamp.
  26. */
  27. public function __construct($owner_id, $updated) {
  28. $this->ownerId = $owner_id;
  29. $this->updated = $updated;
  30. }
  31. /**
  32. * Gets the owner ID.
  33. *
  34. * @return int
  35. * The owner ID.
  36. */
  37. public function getOwnerId() {
  38. return $this->ownerId;
  39. }
  40. /**
  41. * Gets the timestamp of the last update to the lock.
  42. *
  43. * @return int
  44. * The updated timestamp.
  45. */
  46. public function getUpdated() {
  47. return $this->updated;
  48. }
  49. /**
  50. * Provides backwards compatibility for using the lock as a \stdClass object.
  51. */
  52. public function __get($name) {
  53. if ($name === 'owner') {
  54. @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);
  55. return $this->getOwnerId();
  56. }
  57. if ($name === 'updated') {
  58. @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);
  59. return $this->getUpdated();
  60. }
  61. throw new \InvalidArgumentException($name);
  62. }
  63. }