Created
November 29, 2011 22:40
-
-
Save everzet/1406938 to your computer and use it in GitHub Desktop.
Symfony2.1 ResourceWatcher usage example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$watcher = new Symfony\Component\ResourceWatcher\ResourceWatcher; | |
// track any change inside directory: | |
$watcher->track('some/folder1', function($event) { | |
echo '['.$event->getType().'] '.$event->getResource()."\n" | |
}); | |
// track only creations inside directory: | |
$watcher->track('some/folder2', function($event) { | |
echo $event->getResource()." was created\n" | |
}, Symfony\Component\ResourceWatcher\Event\Event::CREATED); | |
// track only *.xml file changes inside directory: | |
$watcher->track( | |
new Symfony\Component\Config\Resource\DirectoryResource('some/folder3', '/\.xml$/'), | |
function($event) use($watcher) { | |
echo '['.$event->getType().'] '.$event->getResource()."\n" | |
// stop tracking when first even occurs: | |
$watcher->stop(); | |
} | |
); | |
// start tracking: | |
$watcher->start(); |
Yes, sounds good to me as well.
How about reversing the order of arguments function track($resource, $alias = null);
?
Well, there should be 3 parameters at least - $resource
, $trackingId
and $trackedEvents
because there's no reason to track any folder change if user only interested in a file_change
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I guess by now everyone are agreeing on accepting both a callable and an object so I would not jump in on that.
I'm more inclined towards @everzet last option. Way easier to understand and use.