*/ class ResourceWatcher { private $tracker; /** @var EventDispatcherInterface|null */ private $eventDispatcher; private $watching = false; /** * Initializes path watcher. * * @param TrackerInterface $tracker * @param EventDispatcherInterface $eventDispatcher */ public function __construct(TrackerInterface $tracker = null, $eventDispatcher = null) { if (null === $tracker) { // TODO: Re-enable InotifyTracker when it's passing its tests. $tracker = new RecursiveIteratorTracker(); //if (function_exists('inotify_init')) { // $tracker = new InotifyTracker(); //} else { // $tracker = new RecursiveIteratorTracker(); //} } if ($eventDispatcher instanceof \Symfony\Component\EventDispatcher\EventDispatcherInterface) { trigger_error( 'In lurkerlite, the ResourceWatcher does not support Symfony EventDispatcher.' . ' See CHANGELOG for upgrade guidance.', E_USER_DEPRECATED ); $eventDispatcher = new EventDispatcher(); } if (null === $eventDispatcher) { $eventDispatcher = new EventDispatcher(); } $this->tracker = $tracker; $this->eventDispatcher = $eventDispatcher; } /** * Returns current tracker instance. * * @return TrackerInterface */ public function getTracker() { return $this->tracker; } /** * Returns event dispatcher mapped to this tracker. * * @return EventDispatcherInterface */ public function getEventDispatcher() { return $this->eventDispatcher; } /** * Track resource with watcher. * * @param string $trackingId id to this track (used for events naming) * @param ResourceInterface|string $resource resource to track * @param integer $eventsMask event types bitmask * * @throws InvalidArgumentException If 'all' is used as a tracking id */ public function track($trackingId, $resource, $eventsMask = FilesystemEvent::ALL) { if ('all' === $trackingId) { throw new InvalidArgumentException( '"all" is a reserved keyword and can not be used as tracking id' ); } if (!$resource instanceof ResourceInterface) { if (is_file($resource)) { $resource = new FileResource($resource); } elseif (is_dir($resource)) { $resource = new DirectoryResource($resource); } else { throw new InvalidArgumentException(sprintf( 'Second argument to track() should be either file or directory resource, '. 'but got "%s"', $resource )); } } $trackedResource = new TrackedResource($trackingId, $resource); $this->getTracker()->track($trackedResource, $eventsMask); } /** * Adds callback as specific tracking listener. * * @param string $trackingId id to this track (used for events naming) * @param callable $callback callback to call on change * * @throws InvalidArgumentException If $callback argument isn't callable */ public function addListener($trackingId, $callback) { if (!is_callable($callback)) { throw new InvalidArgumentException(sprintf( 'Second argument to listen() should be callable, but got %s', gettype($callback) )); } $this->getEventDispatcher()->addListener('resource_watcher.'.$trackingId, $callback); } /** * Tracks specific resource change by provided callback. * * @param ResourceInterface|string $resource resource to track * @param callable $callback callback to call on change * @param integer $eventsMask event types bitmask */ public function trackByListener($resource, $callback, $eventsMask = FilesystemEvent::ALL) { $this->track($trackingId = md5((string) $resource.$eventsMask), $resource, $eventsMask); $this->addListener($trackingId, $callback); } /** * Returns true if watcher is currently watching on tracked resources (started). * * @return Boolean */ public function isWatching() { return $this->watching; } /** * Starts watching on tracked resources. * * @param integer $checkInterval check interval in microseconds * @param integer $timeLimit maximum watching time limit in microseconds */ public function start($checkInterval = 1000000, $timeLimit = null) { $totalTime = 0; $this->watching = true; while ($this->watching) { usleep($checkInterval); $totalTime += $checkInterval; if (null !== $timeLimit && $totalTime > $timeLimit) { break; } foreach ($this->getTracker()->getEvents() as $event) { $trackedResource = $event->getTrackedResource(); // fire global event $this->getEventDispatcher()->dispatch( 'resource_watcher.all', $event ); // fire specific trackingId event $this->getEventDispatcher()->dispatch( sprintf('resource_watcher.%s', $trackedResource->getTrackingId()), $event ); } } $this->watching = false; } /** * Stop watching on tracked resources. */ public function stop() { $this->watching = false; } } __halt_compiler();----SIGNATURE:----p5vYLwbSnLOrTJxFT13rjFLI42rAfVNANS60yWEeomvc74mzO+7f34mPL12KgVlt4Ea21n2GtKglftrWq7Z0TGwdm0hekMfv8Nm3xLWnmfKLi/unPijRBCHTGzhibMYvypzqrHX+ZAPsUhX9LHXvMsC0cHFBIjIA5jSL8ra0sqGESQfy2PahCEXAQlkgy1jCBqQCt9ojQvMdzkj67vJt3faMmy+yd6AKDKflJCT17aGYwNWrt7pqT6gEPd+vadDIJypv9bOVwQZgPYvbvijScjiMFa0UGdtBAXwLZyrAGvyT0EaeadsrIn2arV5ta/c+j5XH3yvpt3rZ1d1Q9P+ZRKN/ou1hGBSJpIcoqzhuAcTrDM4J3O4NTO7Lb+zMTsrfAuD1Lg6X7FcbOT2CE1FF65ikBYgt8ABXz0MuXKeIN3/V/dBO4yReoLWr8xA2Ilt8KS2wHkjDOcQIrGU+oMCVnLm2XZSu/vYLfwJYGBQy+q+gySFPbLIQDLpfRb7kBRNUOFt2s1OtwCOib20Od4Zy+tZxWQsagIdSoaavV2btkORabMIHl1oaFDmvAiNIeljY6794eH2SVXZ/Cn7X8G1kVjlcrH3GY5n6j6pB7bkaTxyfnR60pu6q2Ht41AOCo/x9ZKMR/mql6yPz+mHvp6Bli2G2eViTkklRzwkblT138NE=----ATTACHMENT:----NTkyNTExMjAyNTQwMTkxMyA4ODI1MTE0MjY2NTI3NzkxIDcwOTk4MjEwNjg2ODE3MTg=