util/PearPackageScanner.php
Part of phing, the PHP build tool
PHP version 5
- Author
- Christian Weiske
- Category
- Util
- License
- LGPL v3 or later http://www.gnu.org/licenses/lgpl.html
- Link
- http://www.phing.info/
- Package
- phing.util
- Version
- SVN: $Id: e549026313edf53c67f495489f671cf0b71df80d $
\PearPackageScanner
Scans for files in a PEAR package.
These criteria consist of a set of include and exclude patterns. With these patterns, you can select which files you want to have included, and which files you want to have excluded.
The idea is simple. A given directory is recursively scanned for all files and directories. Each file/directory is matched against a set of include and exclude patterns. Only files/directories that match at least one pattern of the include pattern list, and don't match a pattern of the exclude pattern list will be placed in the list of files/directories found.
When no list of include patterns is supplied, "**" will be used, which means that everything will be matched. When no list of exclude patterns is supplied, an empty list is used, such that nothing will be excluded.
The pattern matching is done as follows: The name to be matched is split up in path segments. A path segment is the name of a directory or file, which is bounded by DIRECTORY_SEPARATOR ('/' under UNIX, '\' under Windows). E.g. "abc/def/ghi/xyz.php" is split up in the segments "abc", "def", "ghi" and "xyz.php". The same is done for the pattern against which should be matched.
Then the segments of the name and the pattern will be matched against each other. When '**' is used for a path segment in the pattern, then it matches zero or more path segments of the name.
There are special case regarding the use of DIRECTORY_SEPARATOR at the beginning of the pattern and the string to match: When a pattern starts with a DIRECTORY_SEPARATOR, the string to match must also start with a DIRECTORY_SEPARATOR. When a pattern does not start with a DIRECTORY_SEPARATOR, the string to match may not start with a DIRECTORY_SEPARATOR. When one of these rules is not obeyed, the string will not match.
When a name path segment is matched against a pattern path segment, the following special characters can be used: '*' matches zero or more characters, '?' matches one character.
Examples:
"***.php" matches all .php files/dirs in a directory tree.
"test\a??.php" matches all files/dirs which start with an 'a', then two more characters and then ".php", in a directory called test.
"**" matches everything in a directory tree.
"**\test*\XYZ" matches all files/dirs that start with "XYZ" and where there is a parent directory called test (e.g. "abc\test\def\ghi\XYZ123").
Case sensitivity may be turned off if necessary. By default, it is turned on.
Example of usage: $ds = new DirectroyScanner(); $includes = array("***.php"); $excludes = array("modules***"); $ds->SetIncludes($includes); $ds->SetExcludes($excludes); $ds->SetBasedir("test"); $ds->SetCaseSensitive(true); $ds->Scan();
print("FILES:"); $files = ds->GetIncludedFiles(); for ($i = 0; $i < count($files);$i++) { println("$files[$i]\n"); }
This will scan a directory called test for .php files, but excludes all .php files in all directories under a directory called "modules"
This class is complete preg/ereg free port of the Java class org.apache.tools.ant.DirectoryScanner. Even functions that use preg/ereg internally (like split()) are not used. Only the fast string functions and comparison operators (=== !=== etc) are used for matching and tokenizing.
- Parent(s)
- \DirectoryScanner < \SelectorScanner
- Author
- Christian Weiske
- Category
- Util
- License
- LGPL v3 or later http://www.gnu.org/licenses/lgpl.html
- Link
- http://www.phing.info/
- Version
- $Id: 7aef4b4e372e89055248ab063660dbee92a98cc3 $
Properties


$DEFAULTEXCLUDES= 'array(
"**/*~",
"**/#*#",
"**/.#*",
"**/%*%",
"**/CVS",
"**/CVS/**",
"**/.cvsignore",
"**/SCCS",
"**/SCCS/**",
"**/vssver.scc",
"**/.svn",
"**/.svn/**",
"**/._*",
"**/.DS_Store",
"**/.darcs",
"**/.darcs/**",
"**/.git",
"**/.git/**",
"**/.gitattributes",
"**/.gitignore",
"**/.gitmodules",
)'
array(
"**/*~",
"**/#*#",
"**/.#*",
"**/%*%",
"**/CVS",
"**/CVS/**",
"**/.cvsignore",
"**/SCCS",
"**/SCCS/**",
"**/vssver.scc",
"**/.svn",
"**/.svn/**",
"**/._*",
"**/.DS_Store",
"**/.darcs",
"**/.darcs/**",
"**/.git",
"**/.git/**",
"**/.gitattributes",
"**/.gitignore",
"**/.gitmodules",
)
Details- Type
- n/a
- Inherited_from
- \DirectoryScanner::$$DEFAULTEXCLUDES


$dirsDeselected= ''
- Type
- n/a
- Inherited_from
- \DirectoryScanner::$$dirsDeselected


$dirsExcluded= ''
The files that where found and matched at least one includes, and also matched at least one excludes.
Inherited from: \DirectoryScanner::$$dirsExcluded- Type
- n/a
- Inherited_from
- \DirectoryScanner::$$dirsExcluded


$dirsIncluded= ''
The directories that where found and matched at least one includes, and matched no excludes.
Inherited from: \DirectoryScanner::$$dirsIncluded- Type
- n/a
- Inherited_from
- \DirectoryScanner::$$dirsIncluded


$dirsNotIncluded= ''
The directories that where found and did not match any includes.
Inherited from: \DirectoryScanner::$$dirsNotIncluded- Type
- n/a
- Inherited_from
- \DirectoryScanner::$$dirsNotIncluded


$everythingIncluded= 'true'
true
Details- Type
- n/a
- Inherited_from
- \DirectoryScanner::$$everythingIncluded


$excludes= 'null'
The patterns for the files that should be excluded.
Inherited from: \DirectoryScanner::$$excludesnull
Details- Type
- n/a
- Inherited_from
- \DirectoryScanner::$$excludes


$expandSymbolicLinks= 'false'
Whether to expand/dereference symbolic links, default is false
Inherited from: \DirectoryScanner::$$expandSymbolicLinksfalse
Details- Type
- n/a
- Inherited_from
- \DirectoryScanner::$$expandSymbolicLinks


$filesDeselected= ''
- Type
- n/a
- Inherited_from
- \DirectoryScanner::$$filesDeselected


$filesExcluded= ''
The files that where found and matched at least one includes, and also matched at least one excludes. Trie object.
Inherited from: \DirectoryScanner::$$filesExcluded- Type
- n/a
- Inherited_from
- \DirectoryScanner::$$filesExcluded


$filesIncluded= ''
The files that where found and matched at least one includes, and matched no excludes.
Inherited from: \DirectoryScanner::$$filesIncluded- Type
- n/a
- Inherited_from
- \DirectoryScanner::$$filesIncluded


$filesNotIncluded= ''
The files that where found and did not match any includes. Trie
Inherited from: \DirectoryScanner::$$filesNotIncluded- Type
- n/a
- Inherited_from
- \DirectoryScanner::$$filesNotIncluded


$haveSlowResults= 'false'
Have the vars holding our results been built by a slow scan?
Inherited from: \DirectoryScanner::$$haveSlowResultsfalse
Details- Type
- n/a
- Inherited_from
- \DirectoryScanner::$$haveSlowResults


$includes= 'null'
The patterns for the files that should be included.
Inherited from: \DirectoryScanner::$$includesnull
Details- Type
- n/a
- Inherited_from
- \DirectoryScanner::$$includes


$isCaseSensitive= 'true'
Should the file system be treated as a case sensitive one?
Inherited from: \DirectoryScanner::$$isCaseSensitivetrue
Details- Type
- n/a
- Inherited_from
- \DirectoryScanner::$$isCaseSensitive
Methods


addDefaultExcludes(
)
:
void
Adds the array with default exclusions to the current exclusions set.
Inherited from: \DirectoryScanner::addDefaultExcludes()

couldHoldIncluded(
\name $_name
)
:
\<code>true</code>
Tests whether a name matches the start of at least one include pattern.
Inherited from: \DirectoryScanner::couldHoldIncluded()Name | Type | Description |
---|---|---|
$_name | \name | the name to match |
Type | Description |
---|---|
\<code>true</code> | when the name matches against at least one include pattern, <code>false</code> otherwise. |


getBasedir(
)
:
\the
Gets the basedir that is used for scanning. This is the directory that is scanned recursively.
Inherited from: \DirectoryScanner::getBasedir()Type | Description |
---|---|
\the | basedir that is used for scanning |


getDeselectedDirectories(
)
:
\the
Returns the names of the directories which were selected out and therefore not ultimately included.
Inherited from: \DirectoryScanner::getDeselectedDirectories()The names are relative to the base directory. This involves performing a slow scan if one has not already been completed.
Type | Description |
---|---|
\the | names of the directories which were deselected. |
- See
- \#slowScan


getDeselectedFiles(
)
:
\the
Returns the names of the files which were selected out and therefore not ultimately included.
Inherited from: \DirectoryScanner::getDeselectedFiles()The names are relative to the base directory. This involves performing a slow scan if one has not already been completed.
Type | Description |
---|---|
\the | names of the files which were deselected. |
- See
- \#slowScan


getExcludedDirectories(
)
:
\the
Get the names of the directories that matched at least one of the include patterns, an matched also at least one of the exclude patterns.
Inherited from: \DirectoryScanner::getExcludedDirectories()The names are relative to the basedir.
Type | Description |
---|---|
\the | names of the directories |


getExcludedFiles(
)
:
\the
Get the names of the files that matched at least one of the include patterns, an matched also at least one of the exclude patterns.
Inherited from: \DirectoryScanner::getExcludedFiles()The names are relative to the basedir.
Type | Description |
---|---|
\the | names of the files |


getIncludedDirectories(
)
:
\the
Get the names of the directories that matched at least one of the include patterns, an matched none of the exclude patterns.
Inherited from: \DirectoryScanner::getIncludedDirectories()The names are relative to the basedir.
Type | Description |
---|---|
\the | names of the directories |


getIncludedFiles(
)
:
\the
Get the names of the files that matched at least one of the include patterns, and matched none of the exclude patterns.
Inherited from: \DirectoryScanner::getIncludedFiles()The names are relative to the basedir.
Type | Description |
---|---|
\the | names of the files |


getNotIncludedDirectories(
)
:
\the
Get the names of the directories that matched at none of the include patterns.
Inherited from: \DirectoryScanner::getNotIncludedDirectories()The names are relative to the basedir.
Type | Description |
---|---|
\the | names of the directories |


getNotIncludedFiles(
)
:
\the
Get the names of the files that matched at none of the include patterns.
Inherited from: \DirectoryScanner::getNotIncludedFiles()The names are relative to the basedir.
Type | Description |
---|---|
\the | names of the files |


isEverythingIncluded(
)
:
\<code>true</code>
Returns whether or not the scanner has included all the files or directories it has come across so far.
Inherited from: \DirectoryScanner::isEverythingIncluded()Type | Description |
---|---|
\<code>true</code> | if all files and directories which have been found so far have been included. |


isExcluded(
\name $_name
)
:
\<code>true</code>
Tests whether a name matches against at least one exclude pattern.
Inherited from: \DirectoryScanner::isExcluded()Name | Type | Description |
---|---|---|
$_name | \name | the name to match |
Type | Description |
---|---|
\<code>true</code> | when the name matches against at least one exclude pattern, <code>false</code> otherwise. |


isIncluded(
\name $_name
)
:
\<code>true</code>
Tests whether a name matches against at least one include pattern.
Inherited from: \DirectoryScanner::isIncluded()Name | Type | Description |
---|---|---|
$_name | \name | the name to match |
Type | Description |
---|---|
\<code>true</code> | when the name matches against at least one include pattern, <code>false</code> otherwise. |


isSelected(
string $name, string $file
)
:
boolean
Name | Type | Description |
---|---|---|
$name | string | The filename to check for selecting. |
$file | string | The full file path. |
Type | Description |
---|---|
boolean | False when the selectors says that the file should not be selected, True otherwise. |


listDir(
\src $_dir
)
:
array
Lists contens of a given directory and returns array with entries
Inherited from: \DirectoryScanner::listDir()Name | Type | Description |
---|---|---|
$_dir | \src | String. Source path and name file to copy. |
Type | Description |
---|---|
array | directory entries |
- Access
- public
- Author
- Albert Lash, alash@plateauinnovation.com


loadPackageInfo(
)
:
\PEAR_PackageFile_v2
Loads and returns the PEAR package information.
Type | Description |
---|---|
\PEAR_PackageFile_v2 | Package information object |
Exception | Description |
---|---|
\BuildException | When the package does not exist |


match(
\pattern $pattern, \str $str, $isCaseSensitive
=
true
)
:
boolean
Matches a string against a pattern. The pattern contains two special characters: '*' which means zero or more characters, '?' which means one and only one character.
Inherited from: \DirectoryScanner::match()Name | Type | Description |
---|---|---|
$pattern | \pattern | the (non-null) pattern to match against |
$str | \str | the (non-null) string that must be matched against the pattern |
$isCaseSensitive |
Type | Description |
---|---|
boolean | true when the string matches against the pattern, false otherwise. |
- Access
- public


matchPath(
\pattern $pattern, \str $str, \isCaseSensitive $isCaseSensitive
=
true
)
:
true
Name | Type | Description |
---|---|---|
$pattern | \pattern | the (non-null) pattern to match against |
$str | \str | the (non-null) string (path) to match |
$isCaseSensitive | \isCaseSensitive | must a case sensitive match be done? |
Type | Description |
---|---|
true | when the pattern matches against the string. false otherwise. |


matchPatternStart(
\pattern $pattern, \str $str, \isCaseSensitive $isCaseSensitive
=
true
)
:
boolean
Does the path match the start of this pattern up to the first "**".
Inherited from: \DirectoryScanner::matchPatternStart()This is a static mehtod and should always be called static
This is not a general purpose test and should only be used if you can live with false positives.
pattern=**\a and str=b will yield true.
Name | Type | Description |
---|---|---|
$pattern | \pattern | the (non-null) pattern to match against |
$str | \str | the (non-null) string (path) to match |
$isCaseSensitive | \isCaseSensitive | must matches be case sensitive? |
Type | Description |
---|---|
boolean | true if matches, otherwise false |


scan(
)
:
boolean
Generates the list of included files and directories
Type | Description |
---|---|
boolean | True if all went well, false if something was wrong |
- Uses
- \$filesIncluded
- Uses
- \$filesDeselected
- Uses
- \$filesNotIncluded
- Uses
- \$filesExcluded
- Uses
- \$everythingIncluded
- Uses
- \$dirsIncluded
- Uses
- \$dirsDeselected
- Uses
- \$dirsNotIncluded
- Uses
- \$dirsExcluded


scandir(
\dir $_rootdir, \vpath $_vpath, $_fast
)
:
void
Scans the passed dir for files and directories. Found files and directories are placed in their respective collections, based on the matching of includes and excludes. When a directory is found, it is scanned recursively.
Inherited from: \DirectoryScanner::scandir()Name | Type | Description |
---|---|---|
$_rootdir | \dir | the directory to scan |
$_vpath | \vpath | the path relative to the basedir (needed to prevent problems with an absolute path when using dir) |
$_fast |
- Access
- private
- See
- \#filesIncluded
- See
- \#filesNotIncluded
- See
- \#filesExcluded
- See
- \#dirsIncluded
- See
- \#dirsNotIncluded
- See
- \#dirsExcluded


setBasedir(
\basedir $_basedir
)
:
void
Sets the basedir for scanning. This is the directory that is scanned recursively. All '/' and '\' characters are replaced by DIRECTORY_SEPARATOR
Inherited from: \DirectoryScanner::setBasedir()Name | Type | Description |
---|---|---|
$_basedir | \basedir | the (non-null) basedir for scanning |


setCaseSensitive(
\specifies $_isCaseSensitive
)
:
void
Sets the case sensitivity of the file system
Inherited from: \DirectoryScanner::setCaseSensitive()Name | Type | Description |
---|---|---|
$_isCaseSensitive | \specifies | if the filesystem is case sensitive |


setChannel(
string $channel
)
:
void
Sets the name of the package channel name
Name | Type | Description |
---|---|---|
$channel | string | package channel name or alias |


setConfig(
string $config
)
:
void
Sets the full path to the PEAR configuration file
Name | Type | Description |
---|---|---|
$config | string | Configuration file |


setExcludes(
\excludes $_excludes
=
array()
)
:
void
Sets the set of exclude patterns to use. All '/' and '\' characters are
replaced by File.separatorChar
. So the separator used need
not match File.separatorChar
.
When a pattern ends with a '/' or '\', "**" is appended.
Name | Type | Description |
---|---|---|
$_excludes | \excludes | list of exclude patterns |


setExpandSymbolicLinks(
\expandSymbolicLinks $expandSymbolicLinks
)
:
void
Sets whether to expand/dereference symbolic links
Inherited from: \DirectoryScanner::setExpandSymbolicLinks()Name | Type | Description |
---|---|---|
$expandSymbolicLinks | \expandSymbolicLinks | boolean value |


setIncludes(
\includes $_includes
=
array()
)
:
void
Sets the set of include patterns to use. All '/' and '\' characters are replaced by DIRECTORY_SEPARATOR. So the separator used need not match DIRECTORY_SEPARATOR.
Inherited from: \DirectoryScanner::setIncludes()When a pattern ends with a '/' or '\', "**" is appended.
Name | Type | Description |
---|---|---|
$_includes | \includes | list of include patterns |


setPackage(
string $package
)
:
void
Sets the name of the PEAR package to get the files from
Name | Type | Description |
---|---|---|
$package | string | Package name without channel |


setSelectors(
\selectors $selectors
)
:
void
Sets the selectors that will select the filelist.
Inherited from: \DirectoryScanner::setSelectors()Name | Type | Description |
---|---|---|
$selectors | \selectors | specifies the selectors to be invoked on a scan |