mirror of
https://github.com/nextcloud/server.git
synced 2026-05-22 01:55:56 -04:00
docs(lock): clarify LockContext API documentation
Signed-off-by: Josh <josh.t.richards@gmail.com>
This commit is contained in:
parent
bb4b32b6b0
commit
82bb73b507
1 changed files with 27 additions and 29 deletions
|
|
@ -12,32 +12,25 @@ namespace OCP\Files\Lock;
|
|||
use OCP\Files\Node;
|
||||
|
||||
/**
|
||||
* Structure to identify a specific lock context to request or
|
||||
* describe a lock with the affected node and ownership information
|
||||
* Value object describing the context in which a lock is requested or evaluated.
|
||||
*
|
||||
* This is used to match a lock/unlock request or file operation to existing locks
|
||||
* A lock context identifies the affected node together with the lock owner type
|
||||
* and owner identifier, so lock-aware operations can be matched against existing locks.
|
||||
*
|
||||
* @since 24.0.0
|
||||
*/
|
||||
final class LockContext {
|
||||
private Node $node;
|
||||
private int $type;
|
||||
private string $owner;
|
||||
|
||||
/**
|
||||
* @param Node $node Node that is owned by the lock
|
||||
* @param int $type Type of the lock owner
|
||||
* @param string $owner Unique identifier for the lock owner based on the type
|
||||
* @param Node $node Node the lock context applies to
|
||||
* @param ILock::TYPE_* $type Lock owner type
|
||||
* @param string $owner Owner identifier for the given type - e.g. a user id, app id, or lock token
|
||||
* @since 24.0.0
|
||||
*/
|
||||
public function __construct(
|
||||
Node $node,
|
||||
int $type,
|
||||
string $owner,
|
||||
private readonly Node $node,
|
||||
private readonly int $type,
|
||||
private readonly string $owner,
|
||||
) {
|
||||
$this->node = $node;
|
||||
$this->type = $type;
|
||||
$this->owner = $owner;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -48,7 +41,9 @@ final class LockContext {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* Returns the lock owner type.
|
||||
*
|
||||
* @return ILock::TYPE_*
|
||||
* @since 24.0.0
|
||||
*/
|
||||
public function getType(): int {
|
||||
|
|
@ -56,7 +51,10 @@ final class LockContext {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return string user id / app id / lock token depending on the type
|
||||
* Returns the owner identifier for the current lock type.
|
||||
*
|
||||
* For example, this may be a user id, app id, or lock token.
|
||||
*
|
||||
* @since 24.0.0
|
||||
*/
|
||||
public function getOwner(): string {
|
||||
|
|
@ -64,19 +62,19 @@ final class LockContext {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a human-readable representation for logging and debugging.
|
||||
*
|
||||
* Not guaranteed to be a stable machine-readable contract.
|
||||
*
|
||||
* @since 24.0.0
|
||||
*/
|
||||
public function __toString(): string {
|
||||
$typeString = 'unknown';
|
||||
if ($this->type === ILock::TYPE_USER) {
|
||||
$typeString = 'ILock::TYPE_USER';
|
||||
}
|
||||
if ($this->type === ILock::TYPE_APP) {
|
||||
$typeString = 'ILock::TYPE_APP';
|
||||
}
|
||||
if ($this->type === ILock::TYPE_TOKEN) {
|
||||
$typeString = 'ILock::TYPE_TOKEN';
|
||||
}
|
||||
return "$typeString $this->owner " . $this->getNode()->getId();
|
||||
$typeString = match ($this->type) {
|
||||
ILock::TYPE_USER => 'ILock::TYPE_USER',
|
||||
ILock::TYPE_APP => 'ILock::TYPE_APP',
|
||||
ILock::TYPE_TOKEN => 'ILock::TYPE_TOKEN',
|
||||
default => 'unknown',
|
||||
};
|
||||
return sprintf('%s %s %d', $typeString, $this->owner, $this->node->getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue