ILock.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\Files\Lock;
  8. /**
  9. * @since 24.0.0
  10. */
  11. interface ILock {
  12. /**
  13. * User owned manual lock
  14. *
  15. * This lock type is initiated by a user manually through the web UI or clients
  16. * and will limit editing capabilities on the file to the lock owning user.
  17. *
  18. * @since 24.0.0
  19. */
  20. public const TYPE_USER = 0;
  21. /**
  22. * App owned lock
  23. *
  24. * This lock type is created by collaborative apps like Text or Office to avoid
  25. * outside changes through WevDAV or other apps.
  26. * @since 24.0.0
  27. *
  28. */
  29. public const TYPE_APP = 1;
  30. /**
  31. * Token owned lock
  32. *
  33. * This lock type will bind the ownership to the provided lock token. Any request
  34. * that aims to modify the file will be required to sent the token, the user
  35. * itself is not able to write to files without the token. This will allow
  36. * to limit the locking to an individual client.
  37. *
  38. * @since 24.0.0
  39. */
  40. public const TYPE_TOKEN = 2;
  41. /**
  42. * WebDAV Lock scope exclusive
  43. *
  44. * @since 24.0.0
  45. */
  46. public const LOCK_EXCLUSIVE = 1;
  47. /**
  48. * WebDAV Lock scope shared
  49. *
  50. * @since 24.0.0
  51. */
  52. public const LOCK_SHARED = 2;
  53. /**
  54. * Lock only the resource the lock is applied to
  55. *
  56. * @since 24.0.0
  57. */
  58. public const LOCK_DEPTH_ZERO = 0;
  59. /**
  60. * Lock app resources under the locked one with infinite depth
  61. *
  62. * @since 24.0.0
  63. */
  64. public const LOCK_DEPTH_INFINITE = -1;
  65. /**
  66. * Type of the lock
  67. *
  68. * @psalm-return ILock::TYPE_*
  69. * @since 24.0.0
  70. */
  71. public function getType(): int;
  72. /**
  73. * Owner that holds the lock
  74. *
  75. * Depending on the lock type this is:
  76. * - ILock::TYPE_USER: A user id
  77. * - ILock::TYPE_APP: An app id
  78. * - ILock::TYPE_TOKEN: A user id
  79. *
  80. * @since 24.0.0
  81. */
  82. public function getOwner(): string;
  83. /**
  84. * File id that the lock is holding
  85. *
  86. * @since 24.0.0
  87. */
  88. public function getFileId(): int;
  89. /**
  90. * Timeout of the lock in seconds starting from the created at time
  91. *
  92. * @since 24.0.0
  93. */
  94. public function getTimeout(): int;
  95. /**
  96. * Unix timestamp of the lock creation time
  97. *
  98. * @since 24.0.0
  99. */
  100. public function getCreatedAt(): int;
  101. /**
  102. * Token string as a unique identifier for the lock, usually a UUID
  103. *
  104. * @since 24.0.0
  105. */
  106. public function getToken(): string;
  107. /**
  108. * Lock depth to apply the lock to child resources
  109. *
  110. * @since 24.0.0
  111. */
  112. public function getDepth(): int;
  113. /**
  114. * WebDAV lock scope
  115. *
  116. * @since 24.0.0
  117. * @psalm-return ILock::LOCK_EXCLUSIVE|ILock::LOCK_SHARED
  118. */
  119. public function getScope(): int;
  120. /**
  121. * String representation of the lock to identify it through logging
  122. *
  123. * @since 24.0.0
  124. */
  125. public function __toString(): string;
  126. }