Skip to content

Commit 06e1228

Browse files
committed
initial commit
0 parents  commit 06e1228

23 files changed

+3161
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
/.idea/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019-present Saif Eddin Gmati <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Assess
2+
3+
Unix filesystem notifications library for PHP.
4+
5+
## Features
6+
7+
- Watch for file creations, modifications, accesses, changes, moves, and deletions.
8+
- Configurable polling interval.
9+
- Filter by file extensions.
10+
- Optionally watch directories.
11+
- Easy-to-use event registration.
12+
13+
## Installation
14+
15+
You can install the library via Composer:
16+
17+
```bash
18+
composer require azjezz/assess
19+
```
20+
21+
## Usage
22+
23+
```php
24+
use Assess\Configuration;
25+
use Assess\Event\Event;
26+
use Assess\Event\EventType;
27+
use Assess\Watcher;
28+
use Revolt\EventLoop;
29+
30+
$configuration = Configuration::createForDirectories([
31+
'/path/to/directory',
32+
'/another/path/to/directory',
33+
])
34+
// poll interval in seconds
35+
->withPollInterval(0.5)
36+
// do not watch directories
37+
->withWatchDirectories(false)
38+
// include only PHP files
39+
->withExtensions(['php'])
40+
;
41+
42+
$watcher = Watcher::create($configuration);
43+
44+
$watcher->register(EventType::Created, function (Event $event): void {
45+
$node = $event->newIndex->nodes[$event->id];
46+
47+
echo "File created: {$node->path}\n";
48+
});
49+
50+
$watcher->register(EventType::Moved, function (Event $event): void {
51+
$oldNode = $event->oldIndex->nodes[$event->id];
52+
$newNode = $event->newIndex->nodes[$event->id];
53+
54+
echo "File moved: {$oldNode->path} -> {$newNode->path}\n";
55+
});
56+
57+
$watcher->register(EventType::Deleted, function (Event $event): void {
58+
$node = $event->oldIndex->nodes[$event->id];
59+
60+
echo "File deleted: {$node->path}\n";
61+
});
62+
63+
$watcher->enable();
64+
$watcher->reference();
65+
66+
EventLoop::run();
67+
```
68+
69+
See [examples/command.php](examples/command.php) for a complete example.
70+
71+
## License
72+
73+
This library is licensed under the MIT license. See the [LICENSE](LICENSE) file for details.

composer.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "azjezz/assess",
3+
"description": "Unix filesystem notification library for PHP",
4+
"type": "library",
5+
"require": {
6+
"php": "^8.3",
7+
"revolt/event-loop": "^1.0",
8+
"amphp/amp": "^3.0",
9+
"amphp/file": "^3.1"
10+
},
11+
"require-dev": {
12+
"ext-pcntl": "*"
13+
},
14+
"license": "MIT",
15+
"autoload": {
16+
"psr-4": {
17+
"Assess\\": "src/"
18+
}
19+
},
20+
"authors": [
21+
{
22+
"name": "azjezz",
23+
"email": "[email protected]"
24+
}
25+
]
26+
}

0 commit comments

Comments
 (0)