Skip to content

Commit b114837

Browse files
committed
Update watcher package description and README
Reflect the general-purpose file watching capability with pluggable drivers and restart strategies. Document config format, watch path syntax, drivers, architecture, and RestartStrategy interface.
1 parent 8ff74a4 commit b114837

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

src/watcher/README.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,79 @@
1-
Watcher for Hypervel
1+
File Watcher for Hypervel
22
===
33

44
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/hypervel/watcher)
5+
6+
A file watcher with pluggable drivers and restart strategies for Hypervel. Detects file changes using coroutine-native drivers and triggers configurable restart actions.
7+
8+
## Configuration
9+
10+
```php
11+
// config/watcher.php
12+
return [
13+
'driver' => ScanFileDriver::class,
14+
'scan_interval' => 2000,
15+
16+
'watch' => [
17+
'app/**/*.php',
18+
'config/**/*.php',
19+
'.env',
20+
],
21+
22+
'bin' => PHP_BINARY,
23+
'command' => 'artisan serve',
24+
];
25+
```
26+
27+
### Watch Paths
28+
29+
Each entry in the `watch` array can be:
30+
31+
- **A directory name**`'app'` watches all files recursively
32+
- **A glob pattern**`'config/**/*.php'` watches only matching files
33+
- **A specific file**`'.env'` or `'composer.json'`
34+
35+
Glob patterns support `*` (single directory segment), `**` (recursive), `?` (single character), and `{a,b}` (alternation), powered by Symfony Finder's glob engine.
36+
37+
### Drivers
38+
39+
| Driver | Description |
40+
|--------|-------------|
41+
| `ScanFileDriver` | Cross-platform, polls files using MD5 checksums |
42+
| `FindDriver` | Uses `find -mmin` (Linux) or `gfind` (macOS via Homebrew) |
43+
| `FindNewerDriver` | Uses `find -newer` with a reference file for comparison |
44+
| `FswatchDriver` | Uses `fswatch` (macOS native or Linux via `apt`/`brew`) |
45+
46+
## Usage
47+
48+
```bash
49+
# Watch and restart server on file changes
50+
php artisan watch
51+
52+
# Watch additional paths beyond config
53+
php artisan watch --path=routes --path=database/**/*.php
54+
55+
# Watch without restarting (detect changes only)
56+
php artisan watch --no-restart
57+
```
58+
59+
## Architecture
60+
61+
The watcher separates three concerns:
62+
63+
- **`Option`** — Parses watch configuration into typed `WatchPath` objects
64+
- **Drivers** (`DriverInterface`) — Detect file changes and push paths to a Channel
65+
- **Restart Strategies** (`RestartStrategy`) — Define what happens when changes are detected
66+
67+
### Restart Strategies
68+
69+
The `RestartStrategy` interface enables different packages to reuse the file watching infrastructure:
70+
71+
```php
72+
interface RestartStrategy
73+
{
74+
public function start(): void;
75+
public function restart(): void;
76+
}
77+
```
78+
79+
The built-in `ServerRestartStrategy` handles Swoole server restart via PID file. Other packages (e.g., Horizon) can implement their own strategy to restart different process types.

src/watcher/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "hypervel/watcher",
33
"type": "library",
4-
"description": "Hot reload watcher for Hypervel development.",
4+
"description": "File watcher with pluggable drivers and restart strategies for Hypervel.",
55
"license": "MIT",
66
"keywords": [
77
"php",

0 commit comments

Comments
 (0)