Skip to content

Commit ae8c54d

Browse files
author
ahmard
committed
Initial Commit
0 parents  commit ae8c54d

File tree

12 files changed

+3019
-0
lines changed

12 files changed

+3019
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.idea/
2+
/vendor/
3+
4+
./composer.lock
5+
/.test1
6+
/.test2
7+
/.test.php
8+
.phpunit.result.cache

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# RTC\Watcher
2+
3+
[Swoole](https://swoole.co.uk) file system changes watcher.
4+
5+
## Installation
6+
7+
```
8+
composer require phprtc/watcher
9+
```
10+
11+
## Usage
12+
13+
#### Basic Usage
14+
15+
```php
16+
use RTC\Watcher\Watcher;
17+
18+
require 'vendor/autoload.php';
19+
20+
Watcher::create()
21+
->addPath(__DIR__ . '/app')
22+
->addPath(__DIR__ . '/views')
23+
//->fileShouldNotEndWith(['.php'])
24+
->onAny(function (EventInfo $eventInfo) {
25+
dump($eventInfo->getMask());
26+
});
27+
```
28+
29+
#### Swoole Server Integration
30+
31+
```php
32+
use Swoole\Http\Request;
33+
use Swoole\Http\Response;
34+
use Swoole\Http\Server;
35+
use RTC\Watcher\Watcher;
36+
37+
require 'vendor/autoload.php';
38+
39+
$server = new Server('0.0.0.0', 9000);
40+
$server->on('request', function (Request $request, Response $response) {
41+
$response->end('Hello world');
42+
});
43+
44+
$server->on('start', function (Server $server) {
45+
echo "Server started at http://0.0.0.0:9000\n";
46+
47+
Watcher::create()
48+
->addPath(__DIR__ . '/app')
49+
->addPath(__DIR__ . '/views')
50+
->onChange(fn() => $server->reload());
51+
});
52+
53+
$server->start();
54+
```

composer.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "phprtc/watcher",
3+
"description": "Swoole File Watcher",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Ahmard",
9+
"email": "ahmardy@outlook.com"
10+
}
11+
],
12+
"require": {
13+
"PHP": "^8.1",
14+
"ext-inotify": "*",
15+
"evenement/evenement": "^3.0"
16+
},
17+
"require-dev": {
18+
"phpstan/phpstan": "^0.12.90",
19+
"phpunit/phpunit": "^9.5",
20+
"symfony/var-dumper": "^6.0",
21+
"openswoole/ide-helper": "^4.10"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"RTC\\Watcher\\": "src/"
26+
}
27+
},
28+
"scripts": {
29+
"analyse" : "vendor/bin/phpstan analyse --debug",
30+
"test" : "vendor/bin/phpunit"
31+
}
32+
}

0 commit comments

Comments
 (0)