diff --git a/README.md b/README.md index 38623f1..b1c418f 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ $watcher->watch( function (FsNotify\Event $event) { var_dump($event->getKind()); // kind of file/folder event var_dump($event->getPaths()); // paths + return true; // return false if you do not want to continue } ); ``` @@ -50,7 +51,7 @@ class RecommendedWatcher public function remove(string $path): void; /** - * @param callable(Event): void $handle + * @param callable(Event): bool $handle * @throws WatchException */ public function watch(callable $handle): void; diff --git a/src/lib.rs b/src/lib.rs index 7972882..42a709d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -190,7 +190,10 @@ pub fn get_module() -> Module { let kind = php_event.get_mut_property("kind"); *kind = php_kind.into(); - handler.call([ZVal::from(php_event)])?; + let call_result = handler.call([ZVal::from(php_event)])?; + if call_result.expect_bool()? == false { + break; + } }, Err(error) => return Err(NotifyError::new(error).into()), } diff --git a/tests/php/recommended_watcher.php b/tests/php/recommended_watcher.php index 367fd3c..b4a49aa 100644 --- a/tests/php/recommended_watcher.php +++ b/tests/php/recommended_watcher.php @@ -12,5 +12,5 @@ $watcher->watch(function (FsNotify\Event $event) { var_dump($event->getKind()); var_dump($event->getPaths()); - exit; + return false; }); diff --git a/tests/php/test_exception.php b/tests/php/test_exception.php index b315451..a4ad6c7 100644 --- a/tests/php/test_exception.php +++ b/tests/php/test_exception.php @@ -7,7 +7,7 @@ try { $watcher = new FsNotify\RecommendedWatcher(); $watcher->add(__DIR__ . '/unknown'); - $watcher->watch(fn () => null); + $watcher->watch(fn () => false); } catch (FsNotify\WatchException) { echo "caught exception"; }