2017 © Pedro Peláez
 

library watcher

A simple watcher library written by PHP.

image

watcher/watcher

A simple watcher library written by PHP.

  • Friday, October 6, 2017
  • by MilesChou
  • Repository
  • 1 Watchers
  • 1 Stars
  • 88 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 1 % Grown

The README.md

Watcher

Codacy Badge Travis CI, (*1)

A simple watcher library written by PHP., (*2)

Usage

Install using Composer, (*3)

$ composer require mileschou/watcher

Watch file

Example of watch file, (*4)

<?php

use Watcher\Watcher;

$watcher = new Watcher();
$watcher->setFile('file1', '/path/to/file');

$watcher->watch(function($alias, $file, $isInit) {
    if ($isInit) {
        return;
    }

    echo $file . ' is Changed';
});

Run once

Example of run one time., (*5)

<?php

use Watcher\Watcher;

$watcher = new Watcher();
$watcher->setFile('file1', '/path/to/file');

$watcher->run(function($alias, $file) {
    echo 'Show ' . $file;
});

Container

You can using simple container, default will trans to ArrayObject, (*6)

<?php

use Watcher\Watcher;

$container = ['something'];

$watcher = new Watcher($container);
$watcher->setFile('file1', '/path/to/file');

$watcher->run(function($alias, $file) {
    /** @var ArrayObject $this */
    $data = $this->getArrayCopy();

    echo 'Container data is ' . $data[0]; // Will see 'something'
});

Or using other container library., (*7)

<?php

use Watcher\Watcher;

$container = new \Pimple\Container();
$container['some-key'] = 'some-value';

$watcher = new Watcher($container);
$watcher->setFile('file1', '/path/to/file');

$watcher->run(function($alias, $file) {
    /** @var \Pimple\Container $this */
    $data = $this['some-key'];

    echo 'Pimple container data is ' . $data; // Will see 'some-value'
});

Strategy

Here are two Strategy can use, (*8)

<?php

use Watcher\Strategy;
use Watcher\Watcher;

// Use inotify extension, it will throw exception if you do not installed
$strategy = new Strategy\Inotify();

// Use file system 
$strategy = new Strategy\FileSystem();

$watcher = new Watcher();
$watcher->setStrategy($strategy);

I guess that using inotify is faster. Actually, I don't know how to test performance., (*9)

The Versions

06/10 2017

dev-master

9999999-dev

A simple watcher library written by PHP.

  Sources   Download

MIT License

The Requires

 

The Development Requires

by Avatar MilesChou

04/02 2017

0.5.1

0.5.1.0

A simple watcher library written by PHP.

  Sources   Download

MIT License

The Requires

 

The Development Requires

by Avatar MilesChou

03/02 2017

0.5.0

0.5.0.0

A simple watcher library written by PHP.

  Sources   Download

MIT License

The Requires

 

The Development Requires

by Avatar MilesChou

25/01 2017

0.4.0

0.4.0.0

A simple watcher library written by PHP.

  Sources   Download

MIT License

The Requires

 

The Development Requires

by Avatar MilesChou

25/01 2017

0.3.0

0.3.0.0

A simple watcher library written by PHP.

  Sources   Download

MIT License

The Requires

  • php >=5.5 | >=7.0

 

The Development Requires

by Avatar MilesChou

24/01 2017

0.2.0

0.2.0.0

A simple watcher library written by PHP.

  Sources   Download

MIT License

The Requires

  • php >=5.5 | >=7.0

 

The Development Requires

by Avatar MilesChou

24/01 2017

0.1.0

0.1.0.0

A simple watcher library written by PHP.

  Sources   Download

MIT License

The Requires

  • php >=5.5 | >=7.0

 

The Development Requires

by Avatar MilesChou