2017 © Pedro Peláez
 

library resource-watcher

A simple resource watcher using Symfony Finder

image

yosymfony/resource-watcher

A simple resource watcher using Symfony Finder

  • Sunday, May 13, 2018
  • by yosymfony
  • Repository
  • 2 Watchers
  • 18 Stars
  • 49,143 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 6 Versions
  • 25 % Grown

The README.md

A simple resource watcher for getting changes of your filesystem., (*1)

Build Status Latest Stable Version, (*2)

Installation

Use Composer to install this package:, (*3)

composer require yosymfony/resource-watcher

How to use?

This package uses Symfony Finder to set the criteria to discover file changes., (*4)

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:, (*5)

  • 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, (*6)

Rebuild cache

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

Relative paths with the resource cache

Using relative paths with the resource cache is possible thanks to the ResourceWatcher's method enableRelativePathWithCache:, (*8)

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

The ResourceWatcherResult object will has relative paths., (*9)

Unit tests

You can run the unit tests with the following command:, (*10)

$ composer test

The Versions

13/05 2018

dev-master

9999999-dev http://yosymfony.com

A simple resource watcher using Symfony Finder

  Sources   Download

MIT

The Requires

 

The Development Requires

symfony resources watcher finder

13/05 2018

v2.0.0

2.0.0.0 http://yosymfony.com

A simple resource watcher using Symfony Finder

  Sources   Download

MIT

The Requires

 

The Development Requires

symfony resources watcher finder

18/02 2018

v1.3.0

1.3.0.0 http://yosymfony.com

A simple resource watcher using Symfony Finder

  Sources   Download

MIT

The Requires

 

The Development Requires

symfony resources watcher finder

14/01 2017

v1.2.0

1.2.0.0 http://yosymfony.com

A simple resource watcher using Symfony Finder

  Sources   Download

MIT

The Requires

 

The Development Requires

symfony resources watcher finder

23/07 2015

v1.1.0

1.1.0.0 http://yosymfony.com

A simple resource watcher using Symfony Finder

  Sources   Download

MIT

The Requires

 

The Development Requires

symfony resources watcher finder

07/01 2015

v1.0.0

1.0.0.0 http://yosymfony.com

A simple resource watcher using Symfony Finder

  Sources   Download

MIT

The Requires

 

The Development Requires

symfony resources watcher finder