PHP Класс Symfony\Component\Finder\Finder

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__);
Автор: Fabien Potencier ([email protected])
Наследование: implements IteratorAggregate, implements Countable
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__construct ( ) Constructor.
addVCSPattern ( string | string[] $pattern ) Adds VCS patterns.
append ( mixed $iterator ) : Finder | Symfony\Component\Finder\SplFileInfo[] Appends an existing set of files/directories to the finder.
contains ( string $pattern ) : Finder | Symfony\Component\Finder\SplFileInfo[] Adds tests that file contents must match.
count ( ) : integer Counts all the results collected by the iterators.
create ( ) : Finder Creates a new Finder.
date ( string $date ) : Finder | Symfony\Component\Finder\SplFileInfo[] Adds tests for file dates (last modified).
depth ( string | integer $level ) : Finder | Symfony\Component\Finder\SplFileInfo[] Adds tests for the directory depth.
directories ( ) : Finder | Symfony\Component\Finder\SplFileInfo[] Restricts the matching to directories only.
exclude ( string | array $dirs ) : Finder | Symfony\Component\Finder\SplFileInfo[] Excludes directories.
files ( ) : Finder | Symfony\Component\Finder\SplFileInfo[] Restricts the matching to files only.
filter ( Closure $closure ) : Finder | Symfony\Component\Finder\SplFileInfo[] Filters the iterator with an anonymous function.
followLinks ( ) : Finder | Symfony\Component\Finder\SplFileInfo[] Forces the following of symlinks.
getIterator ( ) : Iterator | Symfony\Component\Finder\SplFileInfo[] Returns an Iterator for the current Finder configuration.
ignoreDotFiles ( boolean $ignoreDotFiles ) : Finder | Symfony\Component\Finder\SplFileInfo[] Excludes "hidden" directories and files (starting with a dot).
ignoreUnreadableDirs ( boolean $ignore = true ) : Finder | Symfony\Component\Finder\SplFileInfo[] Tells finder to ignore unreadable directories.
ignoreVCS ( boolean $ignoreVCS ) : Finder | Symfony\Component\Finder\SplFileInfo[] Forces the finder to ignore version control directories.
in ( string | array $dirs ) : Finder | Symfony\Component\Finder\SplFileInfo[] Searches files and directories which match defined rules.
name ( string $pattern ) : Finder | Symfony\Component\Finder\SplFileInfo[] Adds rules that files must match.
notContains ( string $pattern ) : Finder | Symfony\Component\Finder\SplFileInfo[] Adds tests that file contents must not match.
notName ( string $pattern ) : Finder | Symfony\Component\Finder\SplFileInfo[] Adds rules that files must not match.
notPath ( string $pattern ) : Finder | Symfony\Component\Finder\SplFileInfo[] Adds rules that filenames must not match.
path ( string $pattern ) : Finder | Symfony\Component\Finder\SplFileInfo[] Adds rules that filenames must match.
size ( string | integer $size ) : Finder | Symfony\Component\Finder\SplFileInfo[] Adds tests for file sizes.
sort ( Closure $closure ) : Finder | Symfony\Component\Finder\SplFileInfo[] Sorts files and directories by an anonymous function.
sortByAccessedTime ( ) : Finder | Symfony\Component\Finder\SplFileInfo[] Sorts files and directories by the last accessed time.
sortByChangedTime ( ) : Finder | Symfony\Component\Finder\SplFileInfo[] Sorts files and directories by the last inode changed time.
sortByModifiedTime ( ) : Finder | Symfony\Component\Finder\SplFileInfo[] Sorts files and directories by the last modified time.
sortByName ( ) : Finder | Symfony\Component\Finder\SplFileInfo[] Sorts files and directories by name.
sortByType ( ) : Finder | Symfony\Component\Finder\SplFileInfo[] Sorts files and directories by type (directories before files), then by name.

Приватные методы

Метод Описание
searchInDirectory ( $dir ) : Iterator

Описание методов

__construct() публичный Метод

Constructor.
public __construct ( )

addVCSPattern() публичный статический Метод

Adds VCS patterns.
См. также: ignoreVCS()
public static addVCSPattern ( string | string[] $pattern )
$pattern string | string[] VCS patterns to ignore

append() публичный Метод

The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
public append ( mixed $iterator ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$iterator mixed
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The finder

contains() публичный Метод

Strings or PCRE patterns can be used: $finder->contains('Lorem ipsum') $finder->contains('/Lorem ipsum/i')
См. также: FilecontentFilterIterator
public contains ( string $pattern ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$pattern string A pattern (string or regexp)
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

count() публичный Метод

Counts all the results collected by the iterators.
public count ( ) : integer
Результат integer

create() публичный статический Метод

Creates a new Finder.
public static create ( ) : Finder
Результат Finder A new Finder instance

date() публичный Метод

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');
См. также: strtotime
См. также: DateRangeFilterIterator
См. также: DateComparator
public date ( string $date ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$date string A date range string
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

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.
См. также: DepthRangeFilterIterator
См. также: NumberComparator
public depth ( string | integer $level ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$level string | integer The depth level expression
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

directories() публичный Метод

Restricts the matching to directories only.
public directories ( ) : Finder | Symfony\Component\Finder\SplFileInfo[]
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

exclude() публичный Метод

Excludes directories.
См. также: ExcludeDirectoryFilterIterator
public exclude ( string | array $dirs ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$dirs string | array A directory path or an array of directories
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

files() публичный Метод

Restricts the matching to files only.
public files ( ) : Finder | Symfony\Component\Finder\SplFileInfo[]
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

filter() публичный Метод

The anonymous function receives a \SplFileInfo and must return false to remove files.
См. также: CustomFilterIterator
public filter ( Closure $closure ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$closure Closure An anonymous function
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

getIterator() публичный Метод

This method implements the IteratorAggregate interface.
public getIterator ( ) : Iterator | Symfony\Component\Finder\SplFileInfo[]
Результат Iterator | Symfony\Component\Finder\SplFileInfo[] An iterator

ignoreDotFiles() публичный Метод

Excludes "hidden" directories and files (starting with a dot).
См. также: ExcludeDirectoryFilterIterator
public ignoreDotFiles ( boolean $ignoreDotFiles ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$ignoreDotFiles boolean Whether to exclude "hidden" files or not
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

ignoreUnreadableDirs() публичный Метод

By default, scanning unreadable directories content throws an AccessDeniedException.
public ignoreUnreadableDirs ( boolean $ignore = true ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$ignore boolean
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

ignoreVCS() публичный Метод

Forces the finder to ignore version control directories.
См. также: ExcludeDirectoryFilterIterator
public ignoreVCS ( boolean $ignoreVCS ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$ignoreVCS boolean Whether to exclude VCS files or not
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

in() публичный Метод

Searches files and directories which match defined rules.
public in ( string | array $dirs ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$dirs string | array A directory path or an array of directories
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

name() публичный Метод

You can use patterns (delimited with / sign), globs or simple strings. $finder->name('*.php') $finder->name('/\.php$/') // same as above $finder->name('test.php')
См. также: FilenameFilterIterator
public name ( string $pattern ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$pattern string A pattern (a regexp, a glob, or a string)
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

notContains() публичный Метод

Strings or PCRE patterns can be used: $finder->notContains('Lorem ipsum') $finder->notContains('/Lorem ipsum/i')
См. также: FilecontentFilterIterator
public notContains ( string $pattern ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$pattern string A pattern (string or regexp)
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

notName() публичный Метод

Adds rules that files must not match.
См. также: FilenameFilterIterator
public notName ( string $pattern ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$pattern string A pattern (a regexp, a glob, or a string)
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

notPath() публичный Метод

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.
См. также: FilenameFilterIterator
public notPath ( string $pattern ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$pattern string A pattern (a regexp or a string)
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

path() публичный Метод

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.
См. также: FilenameFilterIterator
public path ( string $pattern ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$pattern string A pattern (a regexp or a string)
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

size() публичный Метод

$finder->size('> 10K'); $finder->size('<= 1Ki'); $finder->size(4);
См. также: SizeRangeFilterIterator
См. также: NumberComparator
public size ( string | integer $size ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$size string | integer A size range string or an integer
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

sort() публичный Метод

The anonymous function receives two \SplFileInfo instances to compare. This can be slow as all the matching files and directories must be retrieved for comparison.
См. также: SortableIterator
public sort ( Closure $closure ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$closure Closure An anonymous function
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

sortByAccessedTime() публичный Метод

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.
См. также: SortableIterator
public sortByAccessedTime ( ) : Finder | Symfony\Component\Finder\SplFileInfo[]
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

sortByChangedTime() публичный Метод

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.
См. также: SortableIterator
public sortByChangedTime ( ) : Finder | Symfony\Component\Finder\SplFileInfo[]
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

sortByModifiedTime() публичный Метод

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.
См. также: SortableIterator
public sortByModifiedTime ( ) : Finder | Symfony\Component\Finder\SplFileInfo[]
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

sortByName() публичный Метод

This can be slow as all the matching files and directories must be retrieved for comparison.
См. также: SortableIterator
public sortByName ( ) : Finder | Symfony\Component\Finder\SplFileInfo[]
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance

sortByType() публичный Метод

This can be slow as all the matching files and directories must be retrieved for comparison.
См. также: SortableIterator
public sortByType ( ) : Finder | Symfony\Component\Finder\SplFileInfo[]
Результат Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance