monitor = new MtimeMonitor(); printf("Enabling inotify support, watching directories\n"); $this->monitor = new InotifyMonitor(); } else { printf("No inotify support, watching file mtimes\n"); $this->monitor = new MtimeMonitor(); } $this->scriptRunner = get_environment()->getScriptRunner(); } public function addRule(Rule $rule) { if ($rule->getInitialTrigger()) { $this->triggerRule($rule); } $this->rules[] = $rule; $this->monitor->add($rule); } private function triggerRule(Rule $rule) { $actions = $rule->getActions(); $locals = [ 'WATCHER_RULE' => $rule->getName(), 'WATCHER_FILES' => join(" ",$rule->getWatchedFiles()), ]; $this->scriptRunner->evaluate($actions, $locals); } public function loop() { $this->monitor->loop(); $modified = $this->monitor->getModified(); foreach ($modified as $rule) { $this->triggerRule($rule); } } }