6 * Generic filtered source directory
8 class FilteredSourceDir
extends \FilterIterator
implements SourceDir
11 * The Packager command
12 * @var pharext\Command
26 private $filter = [".git/*", ".hg/*"];
30 * @see \pharext\SourceDir::__construct()
32 public function __construct(Command
$cmd, $path) {
36 new \
RecursiveIteratorIterator(
37 new \
RecursiveDirectoryIterator($path,
38 \FilesystemIterator
::KEY_AS_PATHNAME |
39 \FilesystemIterator
::CURRENT_AS_FILEINFO |
40 \FilesystemIterator
::SKIP_DOTS
44 foreach ([".gitignore", ".hgignore"] as $ignore) {
45 if (file_exists("$path/$ignore")) {
46 $this->filter
= array_merge($this->filter
,
47 array_map(function($pat) {
49 if (substr($pat, -1) == '/') {
53 }, file("$path/$ignore",
54 FILE_IGNORE_NEW_LINES |
64 * @see \pharext\SourceDir::getBaseDir()
66 public function getBaseDir() {
71 * Implements FilterIterator
72 * @see FilterIterator::accept()
74 public function accept() {
77 if ($this->cmd
->getArgs()->verbose
) {
78 $this->info("Excluding %s\n", $fn);
82 $pl = strlen($this->path
) +
1;
83 $pn = substr($this->key(), $pl);
84 foreach ($this->filter
as $pat) {
85 if (fnmatch($pat, $pn)) {
86 if ($this->cmd
->getArgs()->verbose
) {
87 $this->info("Excluding %s\n", $pn);
92 if ($this->cmd
->getArgs()->verbose
) {
93 $this->info("Packaging %s\n", $pn);