forked from azjezz/psl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHandleInterface.php
65 lines (58 loc) · 1.76 KB
/
HandleInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace Psl\File;
use Psl\IO;
interface HandleInterface extends IO\CloseSeekStreamHandleInterface
{
/**
* Gets the path to the file.
*/
public function getPath(): string;
/**
* Get the size of the file.
*
* @throws IO\Exception\AlreadyClosedException If the handle has been already closed.
* @throws Exception\RuntimeException If an error occurred during the operation.
*/
public function getSize(): int;
/**
* Get a shared or exclusive lock on the file.
*
* This will block until it acquires the lock, which may be forever.
*
* This involves a blocking syscall; async code will not execute while
* waiting for a lock.
*
* @throws IO\Exception\AlreadyClosedException If the handle has been already closed.
* @throws Exception\RuntimeException If an error occurred during the operation.
*
* Example:
*
* ```php
* $lock = $file->lock(LockType::SHARED);
* // lock has been acquired.
* $lock->release();
* ```
*/
public function lock(LockType $type): Lock;
/**
* Immediately get a shared or exclusive lock on a file, or throw.
*
* @throws IO\Exception\AlreadyClosedException If the handle has been already closed.
* @throws Exception\RuntimeException If an error occurred during the operation.
* @throws Exception\AlreadyLockedException if `lock()` would block.
*
* Example:
*
* ```php
* try {
* $lock = $file->tryLock(LockType::SHARED);
* // lock has been acquired.
* $lock->release();
* } catch(AlreadyLockedException) {
* // cannot acquire lock.
* }
* ```
*/
public function tryLock(LockType $type): Lock;
}