root = $root; } public function setExcluded(array $patterns=[]) { $this->excluded = $patterns; } public function addDirectory($path, callable $filter=null) { $path = rtrim($path, DIRECTORY_SEPARATOR); $obj = (new Finder)->files()->in($path); foreach ($obj as $o) { if (is_callable($filter) && (false === $filter($o))) { continue; } $path = $o->getPathname(); $this->addFile($path); } } public function addFile($file) { // Don't add the file if it matches an excluded pattern if ($this->excluded) foreach ($this->excluded as $p) { if (fnmatch($p, $file)) return; } // Figure out local path name if (strpos($file, $this->root) === 0) { $local = substr($file, 0, strlen($this->root)); } else { $local = $file; } // Add object to manifest $this->objects[] = new ManifestObject($file, $local); } public function getIterator() { return new \ArrayIterator($this->objects); } public function count() { return count($this->objects); } }