1
0

ILock.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2022 Julius Härtl <jus@bitgrid.net>
  5. *
  6. * @author Julius Härtl <jus@bitgrid.net>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCP\Files\Lock;
  25. /**
  26. * @since 24.0.0
  27. */
  28. interface ILock {
  29. /**
  30. * User owned manual lock
  31. *
  32. * This lock type is initiated by a user manually through the web UI or clients
  33. * and will limit editing capabilities on the file to the lock owning user.
  34. *
  35. * @since 24.0.0
  36. */
  37. public const TYPE_USER = 0;
  38. /**
  39. * App owned lock
  40. *
  41. * This lock type is created by collaborative apps like Text or Office to avoid
  42. * outside changes through WevDAV or other apps.
  43. * @since 24.0.0
  44. *
  45. */
  46. public const TYPE_APP = 1;
  47. /**
  48. * Token owned lock
  49. *
  50. * This lock type will bind the ownership to the provided lock token. Any request
  51. * that aims to modify the file will be required to sent the token, the user
  52. * itself is not able to write to files without the token. This will allow
  53. * to limit the locking to an individual client.
  54. *
  55. * @since 24.0.0
  56. */
  57. public const TYPE_TOKEN = 2;
  58. /**
  59. * WebDAV Lock scope exclusive
  60. *
  61. * @since 24.0.0
  62. */
  63. public const LOCK_EXCLUSIVE = 1;
  64. /**
  65. * WebDAV Lock scope shared
  66. *
  67. * @since 24.0.0
  68. */
  69. public const LOCK_SHARED = 2;
  70. /**
  71. * Lock only the resource the lock is applied to
  72. *
  73. * @since 24.0.0
  74. */
  75. public const LOCK_DEPTH_ZERO = 0;
  76. /**
  77. * Lock app resources under the locked one with infinite depth
  78. *
  79. * @since 24.0.0
  80. */
  81. public const LOCK_DEPTH_INFINITE = -1;
  82. /**
  83. * Type of the lock
  84. *
  85. * @psalm-return ILock::TYPE_*
  86. * @since 24.0.0
  87. */
  88. public function getType(): int;
  89. /**
  90. * Owner that holds the lock
  91. *
  92. * Depending on the lock type this is:
  93. * - ILock::TYPE_USER: A user id
  94. * - ILock::TYPE_APP: An app id
  95. * - ILock::TYPE_TOKEN: A user id
  96. *
  97. * @since 24.0.0
  98. */
  99. public function getOwner(): string;
  100. /**
  101. * File id that the lock is holding
  102. *
  103. * @since 24.0.0
  104. */
  105. public function getFileId(): int;
  106. /**
  107. * Timeout of the lock in seconds starting from the created at time
  108. *
  109. * @since 24.0.0
  110. */
  111. public function getTimeout(): int;
  112. /**
  113. * Unix timestamp of the lock creation time
  114. *
  115. * @since 24.0.0
  116. */
  117. public function getCreatedAt(): int;
  118. /**
  119. * Token string as a unique identifier for the lock, usually a UUID
  120. *
  121. * @since 24.0.0
  122. */
  123. public function getToken(): string;
  124. /**
  125. * Lock depth to apply the lock to child resources
  126. *
  127. * @since 24.0.0
  128. */
  129. public function getDepth(): int;
  130. /**
  131. * WebDAV lock scope
  132. *
  133. * @since 24.0.0
  134. * @psalm-return ILock::LOCK_EXCLUSIVE|ILock::LOCK_SHARED
  135. */
  136. public function getScope(): int;
  137. /**
  138. * String representation of the lock to identify it through logging
  139. *
  140. * @since 24.0.0
  141. */
  142. public function __toString(): string;
  143. }