-
-
Notifications
You must be signed in to change notification settings - Fork 0
Basic Usage
Supian M edited this page May 16, 2021
·
5 revisions
use Octopy\Inotify\Inotify;
use Octopy\Inotify\Contract\Event;
use Octopy\Inotify\Contract\Watcher;
$inotify = new Inotify('foo.txt', function (Event $event) {
$event->on(IN_MODIFY, function (Watcher $watcher) {
// do something
});
$event->on(IN_DELETE, function (Watcher $watcher) {
// do something
});
});
$inotify->watch();
Sometimes you want to use dependency injection class instead of the classic way.
use Octopy\Inotify\Inotify;
use Octopy\Inotify\Contract\Event;
use Octopy\Inotify\Contract\Watcher;
class InotifyCommand extends \Illuminate\Console\Command
{
/**
* @param Inotify $inotify
*/
public function __construct(protected Inotify $inotify)
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$this->inotify->source('foobar.txt');
$this->inotify->event(function (Event $event) {
$event->on(IN_MODIFY, function (Watcher $watcher) {
// do something
});
$event->on(IN_DELETE, function (Watcher $watcher) {
// do something
});
});
$this->inotify->watch();
}
}