slick/fswatch 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

slick/fswatch

最新稳定版本:v0.1.0

Composer 安装命令:

composer require slick/fswatch

包简介

slick/fswatch is a simple library that sums the total size of all files in a given directory allowing you to verify if its contents have changed.

README 文档

README

Latest Version Software License Build Status Quality Score Contributor Covenant Total Downloads

slick/fswatch is a simple library that sums the total size of all files in a given directory allowing you to verify if its contents have changed.

This package is compliant with PSR-2 code standards and PSR-4 autoload standards. It also applies the semantic version 2.0.0 specification.

Install

Via Composer

composer require slick/fswatch

Usage

First you need to create a directory snapshot to be able to compare it with any other changes later on:

use Slick\FsWatch\Directory;

$dir = new Directory('/path/to/directory');
// can be stored in any cache or temporary memory to be checked later
$snapshot = $dir->snapshot();
file_put_contents('/some/cache/file', serialize($snapshot)); 

Now you can verify if directory contents have changed:

use Slick\FsWatch\Directory;

$dir = new Directory('/path/to/directory');
$snapshot = unserialize(file_get_contents('/some/cache/file'))

if ($dir->hasChanged($snapshot)) { //directory contents have changed
    $changes = $dir->snapshot()->compareTo($snapshot);
    // do your logic
}

Using as a watcher

Using the same principle above, you can have a daemon like script that will execute a given callback whenever a file changes or is added to a given directory, recursively.

use Slick\FsWatch\Directory;
use Slick\FsWatch\Watcher;

$dir = new Directory('/path/to/directory');

$watcher = new Watcher($dir, function (Directory $dir) => {
    // do your logic on file change
});

// This will run until Ctrl + C (SIGINT) is pressed.
// You can pass an expression of callable to determine the end of the execution
$watcher->watch(Watcher::SIGINT);

Testing

phpunit

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email slick.framework@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 1.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-04