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 [email protected] |
license |
LGPL v3 or later http://www.gnu.org/licenses/lgpl.html |
link |
__construct()
addDefaultExcludes()
couldHoldIncluded(string $_name) : boolean
string
the name to match
boolean
true
when the name matches against at least one
include pattern, false
otherwise.
getBasedir() : string
string
the basedir that is used for scanning
getDeselectedDirectories() : array
The names are relative to the base directory. This involves performing a slow scan if one has not already been completed.
see | \#slowScan |
---|---|
array
the names of the directories which were deselected.
getDeselectedFiles() : array
The names are relative to the base directory. This involves performing a slow scan if one has not already been completed.
see | \#slowScan |
---|---|
array
the names of the files which were deselected.
getExcludedDirectories() : array
The names are relative to the basedir.
array
the names of the directories
getExcludedFiles() : array
The names are relative to the basedir.
array
the names of the files
getIncludedDirectories() : array
The names are relative to the basedir.
array
the names of the directories
getIncludedFiles() : array
The names are relative to the basedir.
array
names of the files
getNotIncludedDirectories() : array
The names are relative to the basedir.
array
the names of the directories
getNotIncludedFiles() : array
The names are relative to the basedir.
array
the names of the files
init() : void
uses | |
---|---|
isEverythingIncluded() : boolean
boolean
true
if all files and directories which have
isExcluded(string $_name) : boolean
string
the name to match
boolean
true
when the name matches against at least one
exclude pattern, false
otherwise.
isIncluded(string $_name) : boolean
string
the name to match
boolean
true
when the name matches against at least one
isSelected(string $name, string $file) : boolean
string
The filename to check for selecting.
string
The full file path.
boolean
False when the selectors says that the file should not be selected, True otherwise.
listDir(string $_dir) : array
author |
Albert Lash, [email protected] |
---|
string
directory to list contents for
array
directory entries
loadPackageInfo() : \PEAR_PackageFile_v2
Throws |
|
---|
\PEAR_PackageFile_v2
Package information object
match(string $pattern, string $str, boolean $isCaseSensitive = true) : boolean
string
pattern to match against
string
string that must be matched against the pattern
boolean
boolean
true when the string matches against the pattern, false otherwise.
matchPath(string $pattern, string $str, boolean $isCaseSensitive = true) : boolean
string
the (non-null) pattern to match against
string
the (non-null) string (path) to match
boolean
must a case sensitive match be done?
boolean
true when the pattern matches against the string. false otherwise.
matchPatternStart(string $pattern, string $str, boolean $isCaseSensitive = true) : 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.
string
the pattern to match against
string
the string (path) to match
boolean
must matches be case sensitive?
boolean
true if matches, otherwise false
scan()
scandir(string $_rootdir, string $_vpath, boolean $_fast)
see | \#filesIncluded \#filesNotIncluded \#filesExcluded \#dirsIncluded \#dirsNotIncluded \#dirsExcluded |
---|---|
string
the directory to scan
string
the path relative to the basedir (needed to prevent problems with an absolute path when using dir)
boolean
setBasedir(string $_basedir)
string
the (non-null) basedir for scanning
setCaseSensitive(boolean $_isCaseSensitive)
boolean
specifies if the filesystem is case sensitive
setChannel(string $channel) : void
string
package channel name or alias
setConfig(string $config) : void
Throws |
|
---|
string
Configuration file
setDescFile(string $descfile) : void
Throws |
|
---|
string
Name of package xml file
setErrorOnMissingDir(boolean $errorOnMissingDir)
boolean
whether or not a missing base directory is an error
setExcludes(array $_excludes = array())
When a pattern ends with a '/' or '\', "**" is appended.
array
list of exclude patterns
setExpandSymbolicLinks(boolean $expandSymbolicLinks)
boolean
setIncludes(array $_includes = array())
When a pattern ends with a '/' or '\', "**" is appended.
array
list of include patterns
setPackage(string $package) : void
string
Package name without channel
setSelectors(array $selectors)
array
the selectors to be invoked on a scan
slowScan()
Returns immediately if a slow scan has already been requested.
packageInfo :
role :
config :
package :
channel :
packageFile :
DEFAULTEXCLUDES :
basedir : string
var |
---|
string
includes : array<mixed,string>
var |
---|
array<mixed,string>
excludes : array<mixed,string>
var |
---|
array<mixed,string>
filesIncluded :
filesNotIncluded :
filesExcluded :
dirsIncluded :
dirsNotIncluded :
dirsExcluded :
haveSlowResults :
isCaseSensitive :
errorOnMissingDir :
selectorsList : array<mixed,\FileSelector>
filesDeselected :
dirsDeselected :
everythingIncluded :