Skip to content

Commit

Permalink
add remove method (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikbosch authored Jun 11, 2024
1 parent e6bafc7 commit 2ac95ee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions tests/php/recommended_watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 2ac95ee

Please sign in to comment.