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
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
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-04