public function testIgnoreAllIterator() { $g = new Glob('test/assets/**', "/"); $regex = $g->regex(); $expect = 4; // 3 files + 1 dir $cnt = 0; foreach ($g->iterate() as $v) { $this->assertRegExp($regex, $v); $cnt++; } $this->assertEquals($expect, $cnt); }
/** * Add a globbing pattern to list. */ public function add($pattern, $script) { if (isset($this->patterns[$pattern])) { if ($script !== $this->patterns[$pattern]['script']) { // fail fast die($pattern . ' has registered!'); } // duplicated pattern, just ignore it return; } $g = new Glob($pattern); $this->patterns[$pattern] = array('script' => $script, 'regexp' => $g->regex(getcwd())); // test if $pattern resolves to single directory $isDir = false; $cnt = 0; foreach ($g->iterate() as $path) { if (!is_dir($path) or $cnt > 1) { break; } $isDir = true; $cnt++; } if ($isDir && $cnt == 1) { $this->patterns[$pattern]['regexp'] = (new Glob($pattern . DIRECTORY_SEPARATOR . '**'))->regex(getcwd()); } // register to inotify $cnt = 0; foreach ($g->iterate() as $path) { if ($this->watched->has($path)) { continue; } if (is_dir($path)) { $this->addDirectory($path); } else { $this->addFile($path); } } }