diff --git a/README.md b/README.md index 4e407d9..db0c38e 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,8 @@ class RecommendedWatcher public function add(string $path, bool $recursive = true): void; + public function remove(string $path): void; + /** * @param callable(Event): void $handle */ diff --git a/src/lib.rs b/src/lib.rs index 2bba88f..0ebead2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,6 +53,16 @@ pub fn get_module() -> Module { .argument(Argument::by_val("path")) .argument(Argument::by_val_optional("recursive")); + watcher.add_method("remove", Visibility::Public, |this, arguments| { + let path = arguments[0].expect_z_str()?; + + let map = this.get_mut_property("map").expect_mut_z_arr()?; + map.remove(path); + + Ok::<_, phper::Error>(()) + }) + .argument(Argument::by_val("path")); + watcher.add_method("watch", Visibility::Public, |this, arguments| { let handler = arguments.get_mut(0).unwrap(); let (tx, rx) = std::sync::mpsc::channel(); diff --git a/tests/php/recommended_watcher.php b/tests/php/recommended_watcher.php index 2858892..367fd3c 100644 --- a/tests/php/recommended_watcher.php +++ b/tests/php/recommended_watcher.php @@ -6,6 +6,8 @@ $watcher = new FsNotify\RecommendedWatcher(); $watcher->add(__DIR__); +$watcher->remove(__DIR__); +$watcher->remove('unknown'); $watcher->add(__DIR__, recursive: false); $watcher->watch(function (FsNotify\Event $event) { var_dump($event->getKind());