定制 yosymfony/resource-watcher 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

yosymfony/resource-watcher

最新稳定版本:v3.0.0

Composer 安装命令:

composer require yosymfony/resource-watcher

包简介

A simple resource watcher using Symfony Finder

README 文档

README

A simple resource watcher for getting changes of your filesystem.

Build Status Latest Stable Version

Installation

Use Composer to install this package:

composer require yosymfony/resource-watcher

How to use?

This package uses Symfony Finder to set the criteria to discover file changes.

use Symfony\Component\Finder\Finder;
use Yosymfony\ResourceWatcher\Crc32ContentHash;
use Yosymfony\ResourceWatcher\ResourceWatcher;
use Yosymfony\ResourceWatcher\ResourceCachePhpFile;

$finder = new Finder();
$finder->files()
    ->name('*.md')
    ->in(__DIR__);

$hashContent = new Crc32ContentHash();
$resourceCache = new ResourceCachePhpFile('/path-cache-file.php');
$watcher = new ResourceWatcher($resourceCache, $finder, $hashContent);
$watcher->initialize();

// delete a file

$result = $watcher->findChanges();

$result->getDeletedResources() // array of deleted filenames. e.g: "/home/yosymfony/README.md"

Finding changes

Every time the method findChanges() of the class ResourceWatcher is invoked, it returns an object type ResourceWatcherResult with information about all the changes producced in the filesystem. The ResourceWatcherResult class has the following methods:

  • getNewFiles(): Returns an array with the paths of the new resources.
  • getDeteledFiles(): Returns an array with the paths of deleted resources.
  • getUpdatedFiles(): Returns an array with the paths of the updated resources.
  • hasChanges(): Are they changes in your resources?.

Hashing alternatives

Two hashing classes are included in the package:

  • Yosymfony\ResourceWatcher\Crc32ContentHash, which hashes the content of the file
  • Yosymfony\ResourceWatcher\Crc32MetaDataHash, which hashes the filename and its last modified timestamp

Rebuild cache

To rebuild the resource cache uses rebuild() method of the class ResourceWatcher.

Relative paths with the resource cache

Using relative paths with the resource cache is possible thanks to the ResourceWatcher's method enableRelativePathWithCache:

$watcher = new ResourceWatcher($resourceCache, $finder, $hashContent);
$watcher->enableRelativePathWithCache()

The ResourceWatcherResult object will has relative paths.

Unit tests

You can run the unit tests with the following command:

$ composer test

统计信息

  • 总下载量: 7.81M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 71
  • 点击次数: 2
  • 依赖项目数: 27
  • 推荐数: 0

GitHub 信息

  • Stars: 69
  • Watchers: 5
  • Forks: 19
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04