crodas/watch-files

监视文件和目录的变化

v0.1.9 2016-08-18 04:46 UTC

This package is auto-updated.

Last update: 2024-09-12 18:38:01 UTC


README

无状态的文件和目录监视方式。

当你编译文件时,如果您需要一个简单高效的方式来监视文件和目录的变化以避免重新编译,这将非常有用。

如何安装

您可以使用composer来安装它。

composer require crodas/watch-files *

如何使用它

require "vendor/autoload.php";

use WatchFiles\Watch;

// we'd like to watch some files
// and to save its state in foobar.php
$foobar = new Watch("foobar.php");
if ($foobar->isWatching()) {
  if (!$foobar->hasChanged()) {
    // somebody else before us started watching files/dirs
    // on foobar.php and *nothing* changed since last 
    // time
    return;
  }
  // do heavy stuff here (Recompile it?)
  // we need to tell the watch that we're aware of lastest
  // changes and we'd like to update the file modification time
  $foobar->rebuild();
  return;
}

// we'd love to see when a new file has been added or deleted
$foobar->watchDir("foodir");
$foobar->watchDirs(array("foodir", 'foobar'));

// or monitor changes inside file or files
$foobar->watchFile("foodir.php");
$foobar->watchFiles(array("foodir.php", 'foobar.php'));

// start watching!
$foobar->watch();