Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Classes

  • Finder
  • Glob
  • SplFileInfo
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo

Class Finder

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__);

Symfony\Component\Finder\Finder implements IteratorAggregate, Countable
Namespace: Symfony\Component\Finder
Author: Fabien Potencier <fabien@symfony.com>
Api
Located at finder/Symfony/Component/Finder/Finder.php
Methods summary
public
# __construct( )

Constructor.

Constructor.

public static Symfony\Component\Finder\Finder
# create( )

Creates a new Finder.

Creates a new Finder.

Returns

Symfony\Component\Finder\Finder
A new Finder instance

Api

public Symfony\Component\Finder\Finder
# addAdapter( Symfony\Component\Finder\Adapter\AdapterInterface $adapter, integer $priority = 0 )

Registers a finder engine implementation.

Registers a finder engine implementation.

Parameters

$adapter
Symfony\Component\Finder\Adapter\AdapterInterface
$adapter An adapter instance
$priority
integer
$priority Highest is selected first

Returns

Symfony\Component\Finder\Finder
The current Finder instance
public Symfony\Component\Finder\Finder
# useBestAdapter( )

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

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

Returns

Symfony\Component\Finder\Finder
The current Finder instance
public Symfony\Component\Finder\Finder
# setAdapter( string $name )

Selects the adapter to use.

Selects the adapter to use.

Parameters

$name
string
$name

Returns

Symfony\Component\Finder\Finder
The current Finder instance

Throws

InvalidArgumentException
public Symfony\Component\Finder\Finder
# removeAdapters( )

Removes all adapters registered in the finder.

Removes all adapters registered in the finder.

Returns

Symfony\Component\Finder\Finder
The current Finder instance
public Symfony\Component\Finder\Adapter\AdapterInterface[]
# getAdapters( )

Returns registered adapters ordered by priority without extra information.

Returns registered adapters ordered by priority without extra information.

Returns

Symfony\Component\Finder\Adapter\AdapterInterface[]
public Symfony\Component\Finder\Finder
# directories( )

Restricts the matching to directories only.

Restricts the matching to directories only.

Returns

Symfony\Component\Finder\Finder
The current Finder instance

Api

public Symfony\Component\Finder\Finder
# files( )

Restricts the matching to files only.

Restricts the matching to files only.

Returns

Symfony\Component\Finder\Finder
The current Finder instance

Api

public Symfony\Component\Finder\Finder
# depth( integer $level )

Adds tests for the directory depth.

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

$level
integer
$level The depth level expression

Returns

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\DepthRangeFilterIterator
Symfony\Component\Finder\Comparator\NumberComparator

Api

public Symfony\Component\Finder\Finder
# date( string $date )

Adds tests for file dates (last modified).

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

$date
string
$date A date rage string

Returns

Symfony\Component\Finder\Finder
The current Finder instance

See

strtotime
Symfony\Component\Finder\Iterator\DateRangeFilterIterator
Symfony\Component\Finder\Comparator\DateComparator

Api

public Symfony\Component\Finder\Finder
# name( string $pattern )

Adds rules that files must match.

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

$pattern
string
$pattern A pattern (a regexp, a glob, or a string)

Returns

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\FilenameFilterIterator

Api

public Symfony\Component\Finder\Finder
# notName( string $pattern )

Adds rules that files must not match.

Adds rules that files must not match.

Parameters

$pattern
string
$pattern A pattern (a regexp, a glob, or a string)

Returns

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\FilenameFilterIterator

Api

public Symfony\Component\Finder\Finder
# contains( string $pattern )

Adds tests that file contents must match.

Adds tests that file contents must match.

Strings or PCRE patterns can be used:

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

Parameters

$pattern
string
$pattern A pattern (string or regexp)

Returns

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\FilecontentFilterIterator
public Symfony\Component\Finder\Finder
# notContains( string $pattern )

Adds tests that file contents must not match.

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

$pattern
string
$pattern A pattern (string or regexp)

Returns

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\FilecontentFilterIterator
public Symfony\Component\Finder\Finder
# path( string $pattern )

Adds rules that filenames must match.

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

$pattern
string
$pattern A pattern (a regexp or a string)

Returns

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\FilenameFilterIterator
public Symfony\Component\Finder\Finder
# notPath( string $pattern )

Adds rules that filenames must not match.

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

$pattern
string
$pattern A pattern (a regexp or a string)

Returns

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\FilenameFilterIterator
public Symfony\Component\Finder\Finder
# size( string $size )

Adds tests for file sizes.

Adds tests for file sizes.

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

Parameters

$size
string
$size A size range string

Returns

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\SizeRangeFilterIterator
Symfony\Component\Finder\Comparator\NumberComparator

Api

public Symfony\Component\Finder\Finder
# exclude( string|array $dirs )

Excludes directories.

Excludes directories.

Parameters

$dirs
string|array
$dirs A directory path or an array of directories

Returns

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator

Api

public Symfony\Component\Finder\Finder
# ignoreDotFiles( Boolean $ignoreDotFiles )

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

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

Parameters

$ignoreDotFiles
Boolean
$ignoreDotFiles Whether to exclude "hidden" files or not

Returns

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator

Api

public Symfony\Component\Finder\Finder
# ignoreVCS( Boolean $ignoreVCS )

Forces the finder to ignore version control directories.

Forces the finder to ignore version control directories.

Parameters

$ignoreVCS
Boolean
$ignoreVCS Whether to exclude VCS files or not

Returns

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator

Api

public static
# addVCSPattern( string|string[] $pattern )

Adds VCS patterns.

Adds VCS patterns.

Parameters

$pattern
string|string[]
$pattern VCS patterns to ignore

See

Symfony\Component\Finder\Finder::ignoreVCS()
public Symfony\Component\Finder\Finder
# sort( Closure $closure )

Sorts files and directories by an anonymous function.

Sorts files and directories by an anonymous function.

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.

Parameters

$closure
Closure
$closure An anonymous function

Returns

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\SortableIterator

Api

public Symfony\Component\Finder\Finder
# sortByName( )

Sorts files and directories by name.

Sorts files and directories by name.

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

Returns

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\SortableIterator

Api

public Symfony\Component\Finder\Finder
# sortByType( )

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

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

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\SortableIterator

Api

public Symfony\Component\Finder\Finder
# sortByAccessedTime( )

Sorts files and directories by the last accessed time.

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

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\SortableIterator

Api

public Symfony\Component\Finder\Finder
# sortByChangedTime( )

Sorts files and directories by the last inode changed time.

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

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\SortableIterator

Api

public Symfony\Component\Finder\Finder
# sortByModifiedTime( )

Sorts files and directories by the last modified time.

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

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\SortableIterator

Api

public Symfony\Component\Finder\Finder
# filter( Closure $closure )

Filters the iterator with an anonymous function.

Filters the iterator with an anonymous function.

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

Parameters

$closure
Closure
$closure An anonymous function

Returns

Symfony\Component\Finder\Finder
The current Finder instance

See

Symfony\Component\Finder\Iterator\CustomFilterIterator

Api

public Symfony\Component\Finder\Finder
# followLinks( )

Forces the following of symlinks.

Forces the following of symlinks.

Returns

Symfony\Component\Finder\Finder
The current Finder instance

Api

public Symfony\Component\Finder\Finder
# in( string|array $dirs )

Searches files and directories which match defined rules.

Searches files and directories which match defined rules.

Parameters

$dirs
string|array
$dirs A directory path or an array of directories

Returns

Symfony\Component\Finder\Finder
The current Finder instance

Throws

InvalidArgumentException
if one of the directories does not exist

Api

public Iterator
# getIterator( )

Returns an Iterator for the current Finder configuration.

Returns an Iterator for the current Finder configuration.

This method implements the IteratorAggregate interface.

Returns

Iterator
An iterator

Throws

LogicException
if the in() method has not been called

Implementation of

IteratorAggregate::getIterator()
public Symfony\Component\Finder\Finder
# append( mixed $iterator )

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

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

$iterator
mixed
$iterator

Returns

Symfony\Component\Finder\Finder
The finder

Throws

InvalidArgumentException
When the given argument is not iterable.
public integer
# count( )

Counts all the results collected by the iterators.

Counts all the results collected by the iterators.

Returns

integer

Implementation of

Countable::count()
Constants summary
integer IGNORE_VCS_FILES 1
#
integer IGNORE_DOT_FILES 2
#
php-coveralls API documentation generated by ApiGen 2.8.0