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.
| category | Util |
|---|---|
| package | phing.util |
| author | Christian Weiske |
| license | LGPL v3 or later http://www.gnu.org/licenses/lgpl.html |
| link | http://www.phing.info/ |
| version | $Id: e092ad3bc1b2a28320f23b721bea34a6c89719c4 $ |
addDefaultExcludes()
| inherited_from | \DirectoryScanner::addDefaultExcludes() |
|---|
getBasedir() : \the
This is the directory that is scanned recursively.
| inherited_from | \DirectoryScanner::getBasedir() |
|---|
\thebasedir that is used for scanninggetDeselectedDirectories() : \the
The names are relative to the base directory. This involves performing a slow scan if one has not already been completed.
| see | \#slowScan |
|---|---|
| inherited_from | \DirectoryScanner::getDeselectedDirectories() |
\thenames of the directories which were deselected.getDeselectedFiles() : \the
The names are relative to the base directory. This involves performing a slow scan if one has not already been completed.
| see | \#slowScan |
|---|---|
| inherited_from | \DirectoryScanner::getDeselectedFiles() |
\thenames of the files which were deselected.getExcludedDirectories() : \the
The names are relative to the basedir.
| inherited_from | \DirectoryScanner::getExcludedDirectories() |
|---|
\thenames of the directoriesgetExcludedFiles() : \the
The names are relative to the basedir.
| inherited_from | \DirectoryScanner::getExcludedFiles() |
|---|
\thenames of the filesgetIncludedDirectories() : \the
The names are relative to the basedir.
| inherited_from | \DirectoryScanner::getIncludedDirectories() |
|---|
\thenames of the directoriesgetIncludedFiles() : \the
The names are relative to the basedir.
| inherited_from | \DirectoryScanner::getIncludedFiles() |
|---|
\thenames of the filesgetNotIncludedDirectories() : \the
The names are relative to the basedir.
| inherited_from | \DirectoryScanner::getNotIncludedDirectories() |
|---|
\thenames of the directoriesgetNotIncludedFiles() : \the
The names are relative to the basedir.
| inherited_from | \DirectoryScanner::getNotIncludedFiles() |
|---|
\thenames of the filesisEverythingIncluded() : \<code>true</code>
| inherited_from | \DirectoryScanner::isEverythingIncluded() |
|---|
\<code>true</code>if all files and directories which have
been found so far have been included.listDir(\src $_dir) : array
| access | public |
|---|---|
| author | Albert Lash, alash@plateauinnovation.com |
| inherited_from | \DirectoryScanner::listDir() |
\srcString. Source path and name file to copy.
arraydirectory entriesmatch(\pattern $pattern, \str $str, $isCaseSensitive) : boolean
The pattern contains two special characters: '*' which means zero or more characters, '?' which means one and only one character.
| access | public |
|---|---|
| inherited_from | \DirectoryScanner::match() |
\patternthe (non-null) pattern to match against
\strthe (non-null) string that must be matched against the pattern
booleantrue when the string matches against the pattern,
false otherwise.matchPath(\pattern $pattern, \str $str, \isCaseSensitive $isCaseSensitive) : true
Static
| inherited_from | \DirectoryScanner::matchPath() |
|---|
\patternthe (non-null) pattern to match against
\strthe (non-null) string (path) to match
\isCaseSensitivemust a case sensitive match be done?
truewhen the pattern matches against the string.
false otherwise.matchPatternStart(\pattern $pattern, \str $str, \isCaseSensitive $isCaseSensitive) : boolean
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.
| inherited_from | \DirectoryScanner::matchPatternStart() |
|---|
\patternthe (non-null) pattern to match against
\strthe (non-null) string (path) to match
\isCaseSensitivemust matches be case sensitive?
booleantrue if matches, otherwise falsescan() : boolean
| uses | \$filesIncluded |
|---|---|
| uses | \$filesDeselected |
| uses | \$filesNotIncluded |
| uses | \$filesExcluded |
| uses | \$everythingIncluded |
| uses | \$dirsIncluded |
| uses | \$dirsDeselected |
| uses | \$dirsNotIncluded |
| uses | \$dirsExcluded |
booleanTrue if all went well, false if something was wrongsetBasedir(\basedir $_basedir)
This is the directory that is scanned recursively. All '/' and '\' characters are replaced by DIRECTORY_SEPARATOR
| inherited_from | \DirectoryScanner::setBasedir() |
|---|
\basedirthe (non-null) basedir for scanning
setCaseSensitive(\specifies $_isCaseSensitive)
| inherited_from | \DirectoryScanner::setCaseSensitive() |
|---|
\specifiesif the filesystem is case sensitive
setChannel(string $channel) : void
stringpackage channel name or alias
setConfig(string $config) : void
stringConfiguration file
setExcludes(\excludes $_excludes)
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.
| inherited_from | \DirectoryScanner::setExcludes() |
|---|
\excludeslist of exclude patterns
setExpandSymbolicLinks(\expandSymbolicLinks $expandSymbolicLinks)
| inherited_from | \DirectoryScanner::setExpandSymbolicLinks() |
|---|
\expandSymbolicLinksboolean value
setIncludes(\includes $_includes)
All '/' and '\' characters are replaced by DIRECTORY_SEPARATOR. So the separator used need not match DIRECTORY_SEPARATOR.
When a pattern ends with a '/' or '\', "**" is appended.
| inherited_from | \DirectoryScanner::setIncludes() |
|---|
\includeslist of include patterns
setPackage(string $package) : void
stringPackage name without channel
setSelectors(\selectors $selectors)
| inherited_from | \DirectoryScanner::setSelectors() |
|---|
\selectorsspecifies the selectors to be invoked on a scan
couldHoldIncluded(\name $_name) : \<code>true</code>
| inherited_from | \DirectoryScanner::couldHoldIncluded() |
|---|
\namethe name to match
\<code>true</code>when the name matches against at least one
include pattern, false otherwise.init() : void
| uses | \$packageInfo |
|---|
isExcluded(\name $_name) : \<code>true</code>
| inherited_from | \DirectoryScanner::isExcluded() |
|---|
\namethe name to match
\<code>true</code>when the name matches against at least one
exclude pattern, false otherwise.isIncluded(\name $_name) : \<code>true</code>
| inherited_from | \DirectoryScanner::isIncluded() |
|---|
\namethe name to match
\<code>true</code>when the name matches against at least one
include pattern, false otherwise.isSelected(string $name, string $file) : boolean
| inherited_from | \DirectoryScanner::isSelected() |
|---|
stringThe filename to check for selecting.
stringThe full file path.
booleanFalse when the selectors says that the file
should not be selected, True otherwise.loadPackageInfo() : \PEAR_PackageFile_v2
\BuildException |
When the package does not exist |
|---|
\PEAR_PackageFile_v2Package information objectslowScan()
Returns immediately if a slow scan has already been requested.
| inherited_from | \DirectoryScanner::slowScan() |
|---|
scandir(\dir $_rootdir, \vpath $_vpath, $_fast)
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.
| access | private |
|---|---|
| see | \#filesIncluded |
| see | \#filesNotIncluded |
| see | \#filesExcluded |
| see | \#dirsIncluded |
| see | \#dirsNotIncluded |
| see | \#dirsExcluded |
| inherited_from | \DirectoryScanner::scandir() |
\dirthe directory to scan
\vpaththe path relative to the basedir (needed to prevent problems with an absolute path when using dir)
$DEFAULTEXCLUDES
| inherited_from | \DirectoryScanner::$$DEFAULTEXCLUDES |
|---|
$basedir
| inherited_from | \DirectoryScanner::$$basedir |
|---|
$channel
$config
$dirsDeselected
| inherited_from | \DirectoryScanner::$$dirsDeselected |
|---|
$dirsExcluded
| inherited_from | \DirectoryScanner::$$dirsExcluded |
|---|
$dirsIncluded
| inherited_from | \DirectoryScanner::$$dirsIncluded |
|---|
$dirsNotIncluded
| inherited_from | \DirectoryScanner::$$dirsNotIncluded |
|---|
$everythingIncluded
| inherited_from | \DirectoryScanner::$$everythingIncluded |
|---|
$excludes
| inherited_from | \DirectoryScanner::$$excludes |
|---|
$filesDeselected
| inherited_from | \DirectoryScanner::$$filesDeselected |
|---|
$filesExcluded
Trie object.
| inherited_from | \DirectoryScanner::$$filesExcluded |
|---|
$filesIncluded
| inherited_from | \DirectoryScanner::$$filesIncluded |
|---|
$filesNotIncluded
Trie
| inherited_from | \DirectoryScanner::$$filesNotIncluded |
|---|
$haveSlowResults
| inherited_from | \DirectoryScanner::$$haveSlowResults |
|---|
$includes
| inherited_from | \DirectoryScanner::$$includes |
|---|
$isCaseSensitive
| inherited_from | \DirectoryScanner::$$isCaseSensitive |
|---|
$package
$packageInfo
$role
$selectors
| inherited_from | \DirectoryScanner::$$selectors |
|---|