1
0

LockContext.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. use OCP\Files\Node;
  9. /**
  10. * Structure to identify a specific lock context to request or
  11. * describe a lock with the affected node and ownership information
  12. *
  13. * This is used to match a lock/unlock request or file operation to existing locks
  14. *
  15. * @since 24.0.0
  16. */
  17. final class LockContext {
  18. private Node $node;
  19. private int $type;
  20. private string $owner;
  21. /**
  22. * @param Node $node Node that is owned by the lock
  23. * @param int $type Type of the lock owner
  24. * @param string $owner Unique identifier for the lock owner based on the type
  25. * @since 24.0.0
  26. */
  27. public function __construct(
  28. Node $node,
  29. int $type,
  30. string $owner
  31. ) {
  32. $this->node = $node;
  33. $this->type = $type;
  34. $this->owner = $owner;
  35. }
  36. /**
  37. * @since 24.0.0
  38. */
  39. public function getNode(): Node {
  40. return $this->node;
  41. }
  42. /**
  43. * @return int
  44. * @since 24.0.0
  45. */
  46. public function getType(): int {
  47. return $this->type;
  48. }
  49. /**
  50. * @return string user id / app id / lock token depending on the type
  51. * @since 24.0.0
  52. */
  53. public function getOwner(): string {
  54. return $this->owner;
  55. }
  56. /**
  57. * @since 24.0.0
  58. */
  59. public function __toString(): string {
  60. $typeString = 'unknown';
  61. if ($this->type === ILock::TYPE_USER) {
  62. $typeString = 'ILock::TYPE_USER';
  63. }
  64. if ($this->type === ILock::TYPE_APP) {
  65. $typeString = 'ILock::TYPE_APP';
  66. }
  67. if ($this->type === ILock::TYPE_TOKEN) {
  68. $typeString = 'ILock::TYPE_TOKEN';
  69. }
  70. return "$typeString $this->owner " . $this->getNode()->getId();
  71. }
  72. }