1212use OCP \Files \Node ;
1313
1414/**
15- * Structure to identify a specific lock context to request or
16- * describe a lock with the affected node and ownership information
15+ * Value object describing the context in which a lock is requested or evaluated.
1716 *
18- * This is used to match a lock/unlock request or file operation to existing locks
17+ * A lock context identifies the affected node together with the lock owner type
18+ * and owner identifier, so lock-aware operations can be matched against existing locks.
1919 *
2020 * @since 24.0.0
2121 */
2222final class LockContext {
23- private Node $ node ;
24- private int $ type ;
25- private string $ owner ;
26-
2723 /**
28- * @param Node $node Node that is owned by the lock
29- * @param int $type Type of the lock owner
30- * @param string $owner Unique identifier for the lock owner based on the type
24+ * @param Node $node Node the lock context applies to
25+ * @param ILock::TYPE_* $type Lock owner type
26+ * @param string $owner Owner identifier for the given type - e.g. a user id, app id, or lock token
3127 * @since 24.0.0
3228 */
3329 public function __construct (
34- Node $ node ,
35- int $ type ,
36- string $ owner ,
30+ private readonly Node $ node ,
31+ private readonly int $ type ,
32+ private readonly string $ owner ,
3733 ) {
38- $ this ->node = $ node ;
39- $ this ->type = $ type ;
40- $ this ->owner = $ owner ;
4134 }
4235
4336 /**
@@ -48,35 +41,40 @@ public function getNode(): Node {
4841 }
4942
5043 /**
51- * @return int
44+ * Returns the lock owner type.
45+ *
46+ * @return ILock::TYPE_*
5247 * @since 24.0.0
5348 */
5449 public function getType (): int {
5550 return $ this ->type ;
5651 }
5752
5853 /**
59- * @return string user id / app id / lock token depending on the type
54+ * Returns the owner identifier for the current lock type.
55+ *
56+ * For example, this may be a user id, app id, or lock token.
57+ *
6058 * @since 24.0.0
6159 */
6260 public function getOwner (): string {
6361 return $ this ->owner ;
6462 }
6563
6664 /**
65+ * Returns a human-readable representation for logging and debugging.
66+ *
67+ * Not guaranteed to be a stable machine-readable contract.
68+ *
6769 * @since 24.0.0
6870 */
6971 public function __toString (): string {
70- $ typeString = 'unknown ' ;
71- if ($ this ->type === ILock::TYPE_USER ) {
72- $ typeString = 'ILock::TYPE_USER ' ;
73- }
74- if ($ this ->type === ILock::TYPE_APP ) {
75- $ typeString = 'ILock::TYPE_APP ' ;
76- }
77- if ($ this ->type === ILock::TYPE_TOKEN ) {
78- $ typeString = 'ILock::TYPE_TOKEN ' ;
79- }
80- return "$ typeString $ this ->owner " . $ this ->getNode ()->getId ();
72+ $ typeString = match ($ this ->type ) {
73+ ILock::TYPE_USER => 'ILock::TYPE_USER ' ,
74+ ILock::TYPE_APP => 'ILock::TYPE_APP ' ,
75+ ILock::TYPE_TOKEN => 'ILock::TYPE_TOKEN ' ,
76+ default => 'unknown ' ,
77+ };
78+ return sprintf ('%s %s %d ' , $ typeString , $ this ->owner , $ this ->node ->getId ());
8179 }
8280}
0 commit comments