1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Inotify; |
6
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use MyCLabs\Enum\Enum; |
9
|
|
|
use UnexpectedValueException; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @method static InotifyEventCodeEnum ON_ACCESS() |
13
|
|
|
* @method static InotifyEventCodeEnum ON_MODIFY() |
14
|
|
|
* @method static InotifyEventCodeEnum ON_ATTRIB(); |
15
|
|
|
* @method static InotifyEventCodeEnum ON_CLOSE_WRITE() |
16
|
|
|
* @method static InotifyEventCodeEnum ON_CLOSE_NOWRITE() |
17
|
|
|
* @method static InotifyEventCodeEnum ON_OPEN() |
18
|
|
|
* @method static InotifyEventCodeEnum ON_MOVED_FROM() |
19
|
|
|
* @method static InotifyEventCodeEnum ON_MOVED_TO() |
20
|
|
|
* @method static InotifyEventCodeEnum ON_CREATE() |
21
|
|
|
* @method static InotifyEventCodeEnum ON_DELETE() |
22
|
|
|
* @method static InotifyEventCodeEnum ON_DELETE_SELF() |
23
|
|
|
* @method static InotifyEventCodeEnum ON_MOVE_SELF() |
24
|
|
|
* @method static InotifyEventCodeEnum ON_UNMOUNT() |
25
|
|
|
* @method static InotifyEventCodeEnum ON_Q_OVERFLOW() |
26
|
|
|
* @method static InotifyEventCodeEnum ON_IGNORED() |
27
|
|
|
* @method static InotifyEventCodeEnum ON_CLOSE() |
28
|
|
|
* @method static InotifyEventCodeEnum ON_MOVE() |
29
|
|
|
* @method static InotifyEventCodeEnum ON_ALL_EVENTS() |
30
|
|
|
* @method static InotifyEventCodeEnum ON_ONLYDIR() |
31
|
|
|
* @method static InotifyEventCodeEnum ON_DONT_FOLLOW() |
32
|
|
|
* @method static InotifyEventCodeEnum ON_MASK_ADD() |
33
|
|
|
* @method static InotifyEventCodeEnum ON_ISDIR() |
34
|
|
|
* @method static InotifyEventCodeEnum ON_ONESHOT() |
35
|
|
|
* @method static InotifyEventCodeEnum ON_CLOSE_NOWRITE_HIGH() |
36
|
|
|
* @method static InotifyEventCodeEnum ON_OPEN_HIGH() |
37
|
|
|
* @method static InotifyEventCodeEnum ON_CREATE_HIGH() |
38
|
|
|
* @method static InotifyEventCodeEnum ON_DELETE_HIGH() |
39
|
|
|
* @method static InotifyEventCodeEnum UNKNOWN() |
40
|
|
|
*/ |
41
|
|
|
class InotifyEventCodeEnum extends Enum |
42
|
|
|
{ |
43
|
|
|
private const ON_ACCESS = 1; |
44
|
|
|
private const ON_MODIFY = 2; |
45
|
|
|
private const ON_ATTRIB = 4; |
46
|
|
|
private const ON_CLOSE_WRITE = 8; |
47
|
|
|
private const ON_CLOSE_NOWRITE = 16; |
48
|
|
|
private const ON_OPEN = 32; |
49
|
|
|
private const ON_MOVED_FROM = 64; |
50
|
|
|
private const ON_MOVED_TO = 128; |
51
|
|
|
private const ON_CREATE = 256; |
52
|
|
|
private const ON_DELETE = 512; |
53
|
|
|
private const ON_DELETE_SELF = 1024; |
54
|
|
|
private const ON_MOVE_SELF = 2048; |
55
|
|
|
private const ON_UNMOUNT = 8192; |
56
|
|
|
private const ON_Q_OVERFLOW = 16384; |
57
|
|
|
private const ON_IGNORED = 32768; |
58
|
|
|
private const ON_CLOSE = 24; |
59
|
|
|
private const ON_MOVE = 192; |
60
|
|
|
private const ON_ALL_EVENTS = 4095; |
61
|
|
|
private const ON_ONLYDIR = 16777216; |
62
|
|
|
private const ON_DONT_FOLLOW = 33554432; |
63
|
|
|
private const ON_MASK_ADD = 536870912; |
64
|
|
|
private const ON_ISDIR = 1073741824; |
65
|
|
|
private const ON_ONESHOT = 2147483648; |
66
|
|
|
|
67
|
|
|
private const ON_CLOSE_NOWRITE_HIGH = 1073741840; |
68
|
|
|
private const ON_OPEN_HIGH = 1073741856; |
69
|
|
|
private const ON_CREATE_HIGH = 1073742080; |
70
|
|
|
private const ON_DELETE_HIGH = 1073742336; |
71
|
|
|
|
72
|
|
|
private const UNKNOWN = 0; |
73
|
|
|
|
74
|
|
|
public static $constants = [ |
75
|
|
|
0 => ['UNKNOWN', 'Unknown code.'], |
76
|
|
|
1 => ['ON_ACCESS', 'File was accessed (read)'], |
77
|
|
|
2 => ['ON_MODIFY', 'File was modified'], |
78
|
|
|
4 => ['ON_ATTRIB', 'Metadata changed (e.g. permissions, mtime, etc.)'], |
79
|
|
|
8 => ['ON_CLOSE_WRITE', 'File opened for writing was closed'], |
80
|
|
|
16 => ['ON_CLOSE_NOWRITE', 'File not opened for writing was closed'], |
81
|
|
|
32 => ['ON_OPEN', 'File was opened'], |
82
|
|
|
128 => ['ON_MOVED_TO', 'File moved into watched directory'], |
83
|
|
|
64 => ['ON_MOVED_FROM', 'File moved out of watched directory'], |
84
|
|
|
256 => ['ON_CREATE', 'File or directory created in watched directory'], |
85
|
|
|
512 => ['ON_DELETE', 'File or directory deleted in watched directory'], |
86
|
|
|
1024 => ['ON_DELETE_SELF', 'Watched file or directory was deleted'], |
87
|
|
|
2048 => ['ON_MOVE_SELF', 'Watch file or directory was moved'], |
88
|
|
|
24 => ['ON_CLOSE', 'Equals to ON_CLOSE_WRITE | ON_CLOSE_NOWRITE'], |
89
|
|
|
192 => ['ON_MOVE', 'Equals to ON_MOVED_FROM | ON_MOVED_TO'], |
90
|
|
|
4095 => ['ON_ALL_EVENTS', 'Bitmask of all the above constants'], |
91
|
|
|
8192 => ['ON_UNMOUNT', 'File system containing watched object was unmounted'], |
92
|
|
|
16384 => ['ON_Q_OVERFLOW', 'Event queue overflowed (wd is -1 for this event)'], |
93
|
|
|
32768 => ['ON_IGNORED', 'Watch was removed (explicitly by inotify_rm_watch() or because file was removed or filesystem unmounted'], |
94
|
|
|
1073741824 => ['ON_ISDIR', 'Subject of this event is a directory'], |
95
|
|
|
1073741840 => ['ON_CLOSE_NOWRITE', 'High-bit: File not opened for writing was closed'], |
96
|
|
|
1073741856 => ['ON_OPEN', 'High-bit: File was opened'], |
97
|
|
|
1073742080 => ['ON_CREATE', 'High-bit: File or directory created in watched directory'], |
98
|
|
|
1073742336 => ['ON_DELETE', 'High-bit: File or directory deleted in watched directory'], |
99
|
|
|
16777216 => ['ON_ONLYDIR', 'Only watch pathname if it is a directory (Since Linux 2.6.15)'], |
100
|
|
|
33554432 => ['ON_DONT_FOLLOW', 'Do not dereference pathname if it is a symlink (Since Linux 2.6.15)'], |
101
|
|
|
536870912 => ['ON_MASK_ADD', 'Add events to watch mask for this pathname if it already exists (instead of replacing mask).'], |
102
|
|
|
2147483648 => ['ON_ONESHOT', 'Monitor pathname for one event, then remove from watch list.'], |
103
|
|
|
]; |
104
|
|
|
|
105
|
2 |
|
public static function getCodeDescription(int $code): string |
106
|
|
|
{ |
107
|
2 |
|
if (!isset(self::$constants[$code])) { |
108
|
|
|
throw new InvalidArgumentException('Unknown code'); |
109
|
|
|
} |
110
|
|
|
|
111
|
2 |
|
return implode(' - ', self::$constants[$code]); |
112
|
|
|
} |
113
|
|
|
|
114
|
2 |
|
public static function createFromMask(int $code): self |
115
|
|
|
{ |
116
|
|
|
try { |
117
|
2 |
|
return new self($code); |
118
|
|
|
} catch (UnexpectedValueException $exception) { |
119
|
|
|
return self::UNKNOWN(); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
} |