diff --git a/README.md b/README.md index 38db411..f9628a1 100644 --- a/README.md +++ b/README.md @@ -73,8 +73,15 @@ be added through one of the rules in the `include` block. stub "src/stub.php"; -In the future, it will also be possible to exclude files matching specific -patterns. +You can follow the same approach when excluding files with the `exclude` block: + + exclude { + dir ".git"; + file "DONT-INCLUDE-ME-IN-PHAR"; + } + +The `dir` rules match against `*//*` while the `file` rule will match +against `*/`. ## Props @@ -153,3 +160,5 @@ into a temporary directory before running. But right now **it does nothing**. them to the archive. This shouldn't be an issue, but if your code depends on a specific character index in a specific php file, you might want to specify the `verbatim` option. +* You can specify multiple `props` blocks, f.ex. one containing static values + and another one generate f.ex. build date or git revision. diff --git a/src/MakePhar/Manifest.php b/src/MakePhar/Manifest.php index 7efdedf..a2d6395 100644 --- a/src/MakePhar/Manifest.php +++ b/src/MakePhar/Manifest.php @@ -23,6 +23,8 @@ class Manifest protected $verbatim = false; /** @var array Properties to be defined in the main stub */ protected $props = []; + /** @var array Patterns to exclude */ + protected $excludes = []; /** * Read manifests from a makephar.sdl file and return all the build targets @@ -74,6 +76,18 @@ class Manifest break; } break; + case 'exclude': + foreach ($child->getChildren() as $inc) switch ($inc->getTagName()) { + case 'dir': + $val = (string)$inc->getValue(); + $mf->excludes[] = "*/{$val}/*"; + break; + case 'file': + $val = (string)$inc->getValue(); + $mf->excludes[] = "*/{$val}"; + break; + } + break; case 'props': $props = []; if ($src = (string)$child->getValue()) { @@ -199,10 +213,18 @@ class Manifest log_warn("Unsupported source type: %s", $source->type); } } - $items = array_filter($items, function ($item) { - if (fnmatch("*/.git/*", $item->src)) return false; + $rules = $this->excludes; + $before = count($items); + $items = array_filter($items, function ($item) use ($rules) { + foreach ($rules as $rule) { + if (fnmatch($rule, $item->src)) return false; + } return true; }); + $after = count($items); + if ($after < $before) { + log_debug("Skipped %d files matching exclusion patterns", $before-$after); + } return $items; }