Created
March 25, 2011 19:21
-
-
Save everzet/887435 to your computer and use it in GitHub Desktop.
New ResourceWatcher component demonstration
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 | |
use Symfony\Component\ResourceWatcher\ResourceWatcher, | |
Symfony\Component\ResourceWatcher\Event\Event, | |
Symfony\Component\Config\Resource\DirectoryResource, | |
Symfony\Component\Config\Resource\FileResource; | |
$watcher = new ResourceWatcher(); | |
$watcher->track(new DirectoryResource('/some/directory'), function($event) { | |
if ($event->getResource() instanceof FileResource) { | |
echo "File [?] " . (string) $event->getResource() . "\n"; | |
} else { | |
echo "Dir [?] " . (string) $event->getResource() . "\n"; | |
} | |
}); | |
$watcher->track(new FileResource('/some/file.txt'), function($event) use ($watcher) { | |
if (false !== strpos((string) $event->getResource(), 'stop_me.txt')) { | |
$watcher->stop(); | |
} | |
if (Event::CREATED === $event->getType()) { | |
echo "File created: " . $event->getType() . " " . (string) $event->getResource() . "\n"; | |
} elseif (Event::MODIFIED === $event->getType()) { | |
echo "File updated: " . $event->getType() . " " . (string) $event->getResource() . "\n"; | |
} elseif (Event::DELETED === $event->getType()) { | |
echo "File deleted: " . $event->getType() . " " . (string) $event->getResource() . "\n"; | |
} | |
}); | |
$watcher->start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment