TYPO3  7.6
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Finder Class Reference
Inheritance diagram for Finder:

Public Member Functions

 __construct ()
 
 addAdapter (AdapterInterface $adapter, $priority=0)
 
 useBestAdapter ()
 
 setAdapter ($name)
 
 removeAdapters ()
 
 getAdapters ()
 
 directories ()
 
 files ()
 
 depth ($level)
 
 date ($date)
 
 name ($pattern)
 
 notName ($pattern)
 
 contains ($pattern)
 
 notContains ($pattern)
 
 path ($pattern)
 
 notPath ($pattern)
 
 size ($size)
 
 exclude ($dirs)
 
 ignoreDotFiles ($ignoreDotFiles)
 
 ignoreVCS ($ignoreVCS)
 
 sort (\Closure $closure)
 
 sortByName ()
 
 sortByType ()
 
 sortByAccessedTime ()
 
 sortByChangedTime ()
 
 sortByModifiedTime ()
 
 filter (\Closure $closure)
 
 followLinks ()
 
 ignoreUnreadableDirs ($ignore=true)
 
 in ($dirs)
 
 getIterator ()
 
 append ($iterator)
 
 count ()
 

Static Public Member Functions

static create ()
 
static addVCSPattern ($pattern)
 

Public Attributes

const IGNORE_VCS_FILES = 1
 
const IGNORE_DOT_FILES = 2
 

Private Member Functions

 sortAdapters ()
 
 searchInDirectory ($dir)
 
 buildAdapter (AdapterInterface $adapter)
 
 resetAdapterSelection ()
 

Private Attributes

 $mode = 0
 
 $names = array()
 
 $notNames = array()
 
 $exclude = array()
 
 $filters = array()
 
 $depths = array()
 
 $sizes = array()
 
 $followLinks = false
 
 $sort = false
 
 $ignore = 0
 
 $dirs = array()
 
 $dates = array()
 
 $iterators = array()
 
 $contains = array()
 
 $notContains = array()
 
 $adapters = array()
 
 $paths = array()
 
 $notPaths = array()
 
 $ignoreUnreadableDirs = false
 

Static Private Attributes

static $vcsPatterns = array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg')
 

Detailed Description

Finder allows to build rules to find files and directories.

It is a thin wrapper around several specialized iterator classes.

All rules may be invoked several times.

All methods return the current Finder object to allow easy chaining:

$finder = Finder::create()->files()->name('*.php')->in(DIR);

Author
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com

Definition at line 45 of file Finder.php.

Constructor & Destructor Documentation

__construct ( )

Constructor.

Definition at line 75 of file Finder.php.

Member Function Documentation

addAdapter ( AdapterInterface  $adapter,
  $priority = 0 
)

Registers a finder engine implementation.

Parameters
AdapterInterface$adapterAn adapter instance
int$priorityHighest is selected first
Returns
Finder The current Finder instance

Definition at line 107 of file Finder.php.

References AdapterInterface\getName(), and Finder\sortAdapters().

static addVCSPattern (   $pattern)
static

Adds VCS patterns.

See Also
ignoreVCS()
Parameters
string|string[]$pattern VCS patterns to ignore

Definition at line 476 of file Finder.php.

append (   $iterator)

Appends an existing set of files/directories to the finder.

The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.

Parameters
mixed$iterator
Returns
Finder The finder
Exceptions
\InvalidArgumentExceptionWhen the given argument is not iterable.

Definition at line 728 of file Finder.php.

References elseif.

buildAdapter ( AdapterInterface  $adapter)
private
Parameters
AdapterInterface$adapter
Returns
AdapterInterface

Definition at line 809 of file Finder.php.

References Finder\contains(), Finder\exclude(), Finder\followLinks(), Finder\ignoreUnreadableDirs(), Finder\notContains(), AdapterInterface\setFollowLinks(), and Finder\sort().

contains (   $pattern)

Adds tests that file contents must match.

Strings or PCRE patterns can be used:

$finder->contains('Lorem ipsum') $finder->contains('/Lorem ipsum/i')

Parameters
string$patternA pattern (string or regexp)
Returns
Finder The current Finder instance
See Also
FilecontentFilterIterator

Definition at line 310 of file Finder.php.

Referenced by Finder\buildAdapter().

count ( )

Counts all the results collected by the iterators.

Returns
int

Definition at line 752 of file Finder.php.

References Finder\getIterator().

Referenced by Finder\getIterator().

static create ( )
static
date (   $date)

Adds tests for file dates (last modified).

The date must be something that strtotime() is able to parse:

$finder->date('since yesterday'); $finder->date('until 2 days ago'); $finder->date('> now - 2 hours'); $finder->date('>= 2005-10-15');

Parameters
string$dateA date range string
Returns
Finder The current Finder instance
See Also
strtotime
DateRangeFilterIterator
DateComparator

Definition at line 247 of file Finder.php.

depth (   $level)

Adds tests for the directory depth.

Usage:

$finder->depth('> 1') // the Finder will start matching at level 1. $finder->depth('< 3') // the Finder will descend at most 3 levels of directories below the starting point.

Parameters
int$levelThe depth level expression
Returns
Finder The current Finder instance
See Also
DepthRangeFilterIterator
NumberComparator

Definition at line 220 of file Finder.php.

directories ( )

Restricts the matching to directories only.

Returns
Finder The current Finder instance

Definition at line 182 of file Finder.php.

exclude (   $dirs)

Excludes directories.

Parameters
string | array$dirsA directory path or an array of directories
Returns
Finder The current Finder instance
See Also
ExcludeDirectoryFilterIterator

Definition at line 418 of file Finder.php.

References Finder\$dirs.

Referenced by Finder\buildAdapter(), and Finder\searchInDirectory().

files ( )

Restricts the matching to files only.

Returns
Finder The current Finder instance

Definition at line 196 of file Finder.php.

filter ( \Closure  $closure)

Filters the iterator with an anonymous function.

The anonymous function receives a and must return false to remove files.

Parameters
\Closure$closureAn anonymous function
Returns
Finder The current Finder instance
See Also
CustomFilterIterator

Definition at line 619 of file Finder.php.

followLinks ( )

Forces the following of symlinks.

Returns
Finder The current Finder instance

Definition at line 633 of file Finder.php.

Referenced by Finder\buildAdapter().

getAdapters ( )

Returns registered adapters ordered by priority without extra information.

Returns
AdapterInterface[]

Definition at line 168 of file Finder.php.

References Finder\$adapters.

getIterator ( )

Returns an Iterator for the current Finder configuration.

This method implements the IteratorAggregate interface.

Returns
An iterator
Exceptions
\LogicExceptionif the in() method has not been called

Definition at line 695 of file Finder.php.

References Finder\count(), and Finder\searchInDirectory().

Referenced by Finder\count().

ignoreDotFiles (   $ignoreDotFiles)

Excludes "hidden" directories and files (starting with a dot).

Parameters
bool$ignoreDotFilesWhether to exclude "hidden" files or not
Returns
Finder The current Finder instance
See Also
ExcludeDirectoryFilterIterator

Definition at line 436 of file Finder.php.

References Finder\IGNORE_DOT_FILES.

ignoreUnreadableDirs (   $ignore = true)

Tells finder to ignore unreadable directories.

By default, scanning unreadable directories content throws an AccessDeniedException.

Parameters
bool$ignore
Returns
Finder The current Finder instance

Definition at line 649 of file Finder.php.

References Finder\$ignore.

Referenced by Finder\buildAdapter().

ignoreVCS (   $ignoreVCS)

Forces the finder to ignore version control directories.

Parameters
bool$ignoreVCSWhether to exclude VCS files or not
Returns
Finder The current Finder instance
See Also
ExcludeDirectoryFilterIterator

Definition at line 458 of file Finder.php.

References Finder\IGNORE_VCS_FILES.

in (   $dirs)

Searches files and directories which match defined rules.

Parameters
string | array$dirsA directory path or an array of directories
Returns
Finder The current Finder instance
Exceptions
\InvalidArgumentExceptionif one of the directories does not exist

Definition at line 667 of file Finder.php.

References Finder\$dirs, and elseif.

name (   $pattern)

Adds rules that files must match.

You can use patterns (delimited with / sign), globs or simple strings.

$finder->name('*.php') $finder->name('/.php$/') // same as above $finder->name('test.php')

Parameters
string$patternA pattern (a regexp, a glob, or a string)
Returns
Finder The current Finder instance
See Also
FilenameFilterIterator

Definition at line 271 of file Finder.php.

notContains (   $pattern)

Adds tests that file contents must not match.

Strings or PCRE patterns can be used:

$finder->notContains('Lorem ipsum') $finder->notContains('/Lorem ipsum/i')

Parameters
string$patternA pattern (string or regexp)
Returns
Finder The current Finder instance
See Also
FilecontentFilterIterator

Definition at line 331 of file Finder.php.

Referenced by Finder\buildAdapter().

notName (   $pattern)

Adds rules that files must not match.

Parameters
string$patternA pattern (a regexp, a glob, or a string)
Returns
Finder The current Finder instance
See Also
FilenameFilterIterator

Definition at line 289 of file Finder.php.

notPath (   $pattern)

Adds rules that filenames must not match.

You can use patterns (delimited with / sign) or simple strings.

$finder->notPath('some/special/dir') $finder->notPath('/some\/special\/dir/') // same as above

Use only / as dirname separator.

Parameters
string$patternA pattern (a regexp or a string)
Returns
Finder The current Finder instance
See Also
FilenameFilterIterator

Definition at line 377 of file Finder.php.

path (   $pattern)

Adds rules that filenames must match.

You can use patterns (delimited with / sign) or simple strings.

$finder->path('some/special/dir') $finder->path('/some\/special\/dir/') // same as above

Use only / as dirname separator.

Parameters
string$patternA pattern (a regexp or a string)
Returns
Finder The current Finder instance
See Also
FilenameFilterIterator

Definition at line 354 of file Finder.php.

removeAdapters ( )

Removes all adapters registered in the finder.

Returns
Finder The current Finder instance

Definition at line 156 of file Finder.php.

resetAdapterSelection ( )
private

Unselects all adapters.

Definition at line 832 of file Finder.php.

References Finder\$adapters.

Referenced by Finder\setAdapter(), and Finder\useBestAdapter().

searchInDirectory (   $dir)
private
Parameters
$dir
Returns
Exceptions
\RuntimeExceptionWhen none of the adapters are supported

Definition at line 780 of file Finder.php.

References Finder\exclude().

Referenced by Finder\getIterator().

setAdapter (   $name)

Selects the adapter to use.

Parameters
string$name
Exceptions
\InvalidArgumentException
Returns
Finder The current Finder instance

Definition at line 139 of file Finder.php.

References Finder\resetAdapterSelection(), and Finder\sortAdapters().

size (   $size)

Adds tests for file sizes.

$finder->size('> 10K'); $finder->size('<= 1Ki'); $finder->size(4);

Parameters
string$sizeA size range string
Returns
Finder The current Finder instance
See Also
SizeRangeFilterIterator
NumberComparator

Definition at line 400 of file Finder.php.

sort ( \Closure  $closure)

Sorts files and directories by an anonymous function.

The anonymous function receives two instances to compare.

This can be slow as all the matching files and directories must be retrieved for comparison.

Parameters
\Closure$closureAn anonymous function
Returns
Finder The current Finder instance
See Also
SortableIterator

Definition at line 500 of file Finder.php.

Referenced by Finder\buildAdapter(), Finder\sortByAccessedTime(), Finder\sortByChangedTime(), Finder\sortByModifiedTime(), Finder\sortByName(), and Finder\sortByType().

sortAdapters ( )
private
Returns
Finder The current Finder instance

Definition at line 760 of file Finder.php.

Referenced by Finder\addAdapter(), Finder\setAdapter(), and Finder\useBestAdapter().

sortByAccessedTime ( )

Sorts files and directories by the last accessed time.

This is the time that the file was last accessed, read or written to.

This can be slow as all the matching files and directories must be retrieved for comparison.

Returns
Finder The current Finder instance
See Also
SortableIterator

Definition at line 556 of file Finder.php.

References Finder\sort().

sortByChangedTime ( )

Sorts files and directories by the last inode changed time.

This is the time that the inode information was last modified (permissions, owner, group or other metadata).

On Windows, since inode is not available, changed time is actually the file creation time.

This can be slow as all the matching files and directories must be retrieved for comparison.

Returns
Finder The current Finder instance
See Also
SortableIterator

Definition at line 578 of file Finder.php.

References Finder\sort().

sortByModifiedTime ( )

Sorts files and directories by the last modified time.

This is the last time the actual contents of the file were last modified.

This can be slow as all the matching files and directories must be retrieved for comparison.

Returns
Finder The current Finder instance
See Also
SortableIterator

Definition at line 598 of file Finder.php.

References Finder\sort().

sortByName ( )

Sorts files and directories by name.

This can be slow as all the matching files and directories must be retrieved for comparison.

Returns
Finder The current Finder instance
See Also
SortableIterator

Definition at line 518 of file Finder.php.

References Finder\sort().

sortByType ( )

Sorts files and directories by type (directories before files), then by name.

This can be slow as all the matching files and directories must be retrieved for comparison.

Returns
Finder The current Finder instance
See Also
SortableIterator

Definition at line 536 of file Finder.php.

References Finder\sort().

useBestAdapter ( )

Sets the selected adapter to the best one according to the current platform the code is run on.

Returns
Finder The current Finder instance

Definition at line 123 of file Finder.php.

References Finder\resetAdapterSelection(), and Finder\sortAdapters().

Member Data Documentation

$adapters = array()
private

Definition at line 65 of file Finder.php.

Referenced by Finder\getAdapters(), and Finder\resetAdapterSelection().

$contains = array()
private

Definition at line 63 of file Finder.php.

$dates = array()
private

Definition at line 61 of file Finder.php.

$depths = array()
private

Definition at line 55 of file Finder.php.

$dirs = array()
private

Definition at line 60 of file Finder.php.

Referenced by Finder\exclude(), and Finder\in().

$exclude = array()
private

Definition at line 53 of file Finder.php.

$filters = array()
private

Definition at line 54 of file Finder.php.

$followLinks = false
private

Definition at line 57 of file Finder.php.

$ignore = 0
private

Definition at line 59 of file Finder.php.

Referenced by Finder\ignoreUnreadableDirs().

$ignoreUnreadableDirs = false
private

Definition at line 68 of file Finder.php.

$iterators = array()
private

Definition at line 62 of file Finder.php.

$mode = 0
private

Definition at line 50 of file Finder.php.

$names = array()
private

Definition at line 51 of file Finder.php.

$notContains = array()
private

Definition at line 64 of file Finder.php.

$notNames = array()
private

Definition at line 52 of file Finder.php.

$notPaths = array()
private

Definition at line 67 of file Finder.php.

$paths = array()
private

Definition at line 66 of file Finder.php.

$sizes = array()
private

Definition at line 56 of file Finder.php.

$sort = false
private

Definition at line 58 of file Finder.php.

$vcsPatterns = array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg')
staticprivate

Definition at line 70 of file Finder.php.

const IGNORE_DOT_FILES = 2

Definition at line 48 of file Finder.php.

Referenced by Finder\ignoreDotFiles().

const IGNORE_VCS_FILES = 1

Definition at line 47 of file Finder.php.

Referenced by Finder\ignoreVCS().