|
@@ -29,6 +29,9 @@ namespace Symfony\Component\Finder;
|
|
|
*/
|
|
|
class Finder implements \IteratorAggregate
|
|
|
{
|
|
|
+ const IGNORE_VCS_FILES = 1;
|
|
|
+ const IGNORE_DOT_FILES = 2;
|
|
|
+
|
|
|
private $mode = 0;
|
|
|
private $names = array();
|
|
|
private $notNames = array();
|
|
@@ -38,11 +41,18 @@ class Finder implements \IteratorAggregate
|
|
|
private $sizes = array();
|
|
|
private $followLinks = false;
|
|
|
private $sort = false;
|
|
|
- private $ignoreVCS = true;
|
|
|
+ private $ignore = 0;
|
|
|
private $dirs = array();
|
|
|
private $dates = array();
|
|
|
private $iterators = array();
|
|
|
|
|
|
+ static private $vcsPatterns = array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg');
|
|
|
+
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->ignore = static::IGNORE_VCS_FILES | static::IGNORE_DOT_FILES;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Restricts the matching to directories only.
|
|
|
*
|
|
@@ -205,22 +215,55 @@ class Finder implements \IteratorAggregate
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Excludes "hidden" directories and files (starting with a dot).
|
|
|
+ *
|
|
|
+ * @param Boolean $ignoreDotFiles Whether to exclude "hidden" files or not
|
|
|
+ *
|
|
|
+ * @return Finder The current Finder instance
|
|
|
+ *
|
|
|
+ * @see Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator
|
|
|
+ *
|
|
|
+ * @api
|
|
|
+ */
|
|
|
+ public function ignoreDotFiles($ignoreDotFiles)
|
|
|
+ {
|
|
|
+ if ($ignoreDotFiles) {
|
|
|
+ $this->ignore = $this->ignore | static::IGNORE_DOT_FILES;
|
|
|
+ } else {
|
|
|
+ $this->ignore = $this->ignore ^ static::IGNORE_DOT_FILES;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Forces the finder to ignore version control directories.
|
|
|
*
|
|
|
+ * @param Boolean $ignoreVCS Whether to exclude VCS files or not
|
|
|
+ *
|
|
|
* @return Finder The current Finder instance
|
|
|
*
|
|
|
- * @see Symfony\Component\Finder\Iterator\IgnoreVcsFilterIterator
|
|
|
+ * @see Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator
|
|
|
*
|
|
|
* @api
|
|
|
*/
|
|
|
public function ignoreVCS($ignoreVCS)
|
|
|
{
|
|
|
- $this->ignoreVCS = (Boolean) $ignoreVCS;
|
|
|
+ if ($ignoreVCS) {
|
|
|
+ $this->ignore = $this->ignore | static::IGNORE_VCS_FILES;
|
|
|
+ } else {
|
|
|
+ $this->ignore = $this->ignore ^ static::IGNORE_VCS_FILES;
|
|
|
+ }
|
|
|
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
+ static public function addVCSPattern($pattern)
|
|
|
+ {
|
|
|
+ static::$vcsPatterns[] = $pattern;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Sorts files and directories by an anonymous function.
|
|
|
*
|
|
@@ -416,12 +459,16 @@ class Finder implements \IteratorAggregate
|
|
|
$iterator = new Iterator\FileTypeFilterIterator($iterator, $this->mode);
|
|
|
}
|
|
|
|
|
|
- if ($this->exclude) {
|
|
|
- $iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
|
|
|
+ if (static::IGNORE_VCS_FILES === (static::IGNORE_VCS_FILES & $this->ignore)) {
|
|
|
+ $this->exclude = array_merge($this->exclude, static::$vcsPatterns);
|
|
|
}
|
|
|
|
|
|
- if ($this->ignoreVCS) {
|
|
|
- $iterator = new Iterator\IgnoreVcsFilterIterator($iterator);
|
|
|
+ if (static::IGNORE_DOT_FILES === (static::IGNORE_DOT_FILES & $this->ignore)) {
|
|
|
+ $this->exclude[] = '\..+';
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->exclude) {
|
|
|
+ $iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
|
|
|
}
|
|
|
|
|
|
if ($this->names || $this->notNames) {
|