*/ class InotifyTracker implements TrackerInterface { /** @var array */ protected $checkers = array(); /** @var CheckerBag */ protected $bag; /** @var resource Inotify resource. */ private $inotify; /** * Initializes tracker. Creates inotify resource used to track file and directory changes. * * @throws RuntimeException If inotify extension unavailable */ public function __construct() { if (!function_exists('inotify_init')) { throw new RuntimeException('You must install inotify to be able to use this tracker.'); } $this->inotify = inotify_init(); stream_set_blocking($this->inotify, 0); $this->bag = new CheckerBag($this->inotify); } /** * {@inheritdoc} */ public function track(TrackedResource $resource, $eventsMask = FilesystemEvent::ALL) { $trackingId = $resource->getTrackingId(); $checker = $resource->getOriginalResource() instanceof DirectoryResource ? new TopDirectoryStateChecker($this->bag, $resource->getOriginalResource(), $eventsMask) : new FileStateChecker($this->bag, $resource->getOriginalResource(), $eventsMask); $this->checkers[$trackingId] = array( 'tracked' => $resource, 'checker' => $checker ); } /** * {@inheritdoc} * * @throws RuntimeException If event queue overflowed */ public function getEvents() { $inotifyEvents = $this->readEvents(); $inotifyEvents = is_array($inotifyEvents) ? $inotifyEvents : array(); $last = end($inotifyEvents); if (IN_Q_OVERFLOW === $last['mask']) { throw new RuntimeException('Event queue overflowed. Either read events more frequently or increase the limit for queues. The limit can be changed in /proc/sys/fs/inotify/max_queued_events'); } foreach ($inotifyEvents as $event) { foreach ($this->bag->get($event['wd']) as $watched) { $watched->setEvent($event['mask'], $event['name']); } } $events = array(); foreach ($this->checkers as $meta) { $tracked = $meta['tracked']; $watched = $meta['checker']; foreach ($watched->getChangeset() as $change) { $events[] = new FilesystemEvent($tracked, $change['resource'], $change['event']); } } return $events; } /** * Closes the inotify resource. */ public function __destruct() { fclose($this->inotify); } /** * Returns all events happened since last event readout * * @return array */ protected function readEvents() { return inotify_read($this->inotify); } } __halt_compiler();----SIGNATURE:----SQikNmMDuYb2C4FGKtmtc35Apl0mmvqzi77RaSAx+o4qf9p6ymsHw5tLENEPD5MZcG4gwocP2lhPX74EqYayH/eoQCJYTZOZZcVVkCI27g+VtMCEJvT5gbOmBPSnJRdw225QU2H3oqySpIdZ7UrLKcSRKj04nlYWfofEAge69Fm6V0qlFr19WbHtP8fLNxgOE1dJEt38tsE2JzbSt+l1pxAk8udLlGU44MR6+1VZ3Vd844IxiljkHGV3r014itZimWiPBNf0yn8D0KmtjnMsUMxqKT24OIRZJbb+mogCNn48m94FtxokBZtU/JXI52Fd8cVHHR/ND+8ce51xBNW2W382bbY+KOeGOt5yy1qbCOkuoPwnGMn9TL31SXV4O7TnDcKotYbBvwYsZFKie46zewDptkvWwfQSNDe7c/V2fy24tZ99C6IAlvD7V9U3MEbiYCLKy1HzkpvnuOghWkchOMYrGcSLTpax02FpE4VD9+a+n/f6CGd1QlsKSEIzWCBWUZo+U+dLeoINYVHb4ayooxJrycciQdMT4uFRd6dLd+03LxEjL53Tm+MzT4ldO6rdC0VOBoSS3hmw9V4nBpeI0Iybbwa/5SGn02hiRMJi/bYnLjlkrtUaL19kBR5bhBMlQl9MuzmYFUE32pXYfkHImqJTJUt8WLs22Qu7QMpa2WU=----ATTACHMENT:----MjkwMzgxMTAyNTAwODcwMiA5MDg4OTc0NzQ4MzY2MzgyIDE2NTM1MzQ5NjQwNTg0NTU=