Skip to content

Commit

Permalink
Modify docs
Browse files Browse the repository at this point in the history
  • Loading branch information
huang-yi committed Jan 17, 2020
1 parent a875d6f commit b25f637
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,43 @@

This package provides a file watcher.

## Usage
## Installation

The current version only supports [fswatch](https://github.com/emcrisostomo/fswatch), so you'll have to install fswatch first.

```sh
# MacOS
brew install fswatch

# Linux (building from Source)
wget https://github.com/emcrisostomo/fswatch/releases/download/{VERSION}/fswatch-{VERSION}.tar.gz
tar -xzvf fswatch-{VERSION}.tar.gz
cd fswatch-{VERSION} && ./configure && make && sudo make install && sudo ldconfig
```

> A user who wishes to build fswatch should get a release [tarball](https://github.com/emcrisostomo/fswatch/releases)
Then, make sure you have [swoole](https://www.swoole.co.uk/) extension installed in PHP.

```sh
pecl install swoole
```

You may install Swoole Unit via Composer:
Finally, you may install the Swoole Watcher via Composer:

```sh
$ composer require huang-yi/swoole-watcher
composer require huang-yi/swoole-watcher
```

Then, create your watcher script.
## Usage

Create your watcher script like this:

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use HuangYi\Watcher\Commands\Fswatch;
use HuangYi\Watcher\Watcher;

Expand All @@ -27,16 +51,20 @@ $command->setOptions([

$watcher = new Watcher($command);

$watcher->onChange(function () {
// Registers a callback for an event.
$watcher->on(Fswatch::CREATED, function ($path) {
// do something...
});

// or registers a default callback for any event.
$watcher->onChange(function ($events) {
// do something...
});

$watcher->start();

```

You can stop watch by using `$watcher->stop()`.

## License

Swoole Unit is open-sourced software licensed under the [MIT license](LICENSE).
Swoole Watcher is open-sourced software licensed under the [MIT license](LICENSE).

0 comments on commit b25f637

Please sign in to comment.