Overview

Namespaces

  • KeepItSimple
    • FileSystem

Classes

  • Finder
  • Overview
  • Namespace
  • Class

Class Finder

Finder finds files and directories via a set of rules. 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__);
KeepItSimple\FileSystem\Finder implements IteratorAggregate, Countable
Namespace: KeepItSimple\FileSystem
Package: KeepItSimple\FileSystem\Finder
Author: Alexandre Debusschere (debuss-a)
Implements: IteratorAggregate
Implements: Countable
Located at Finder.php
Methods summary
public
# __construct( )

Finder constructor. No parameters needed.

Finder constructor. No parameters needed.

public static KeepItSimple\FileSystem\Finder
# create( )

Create a Finder instance and returns it. Equivalent to :

$finder = (new Finder())->in(__DIR__);

Create a Finder instance and returns it. Equivalent to :

$finder = (new Finder())->in(__DIR__);

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# files( )

Restricts the matching to files only.

Restricts the matching to files only.

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# directories( )

Restricts the matching to directories only.

Restricts the matching to directories only.

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# in( string|array $directories )

Searches files and/or directories in the given path(s).

Searches files and/or directories in the given path(s).

Parameters

$directories

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# exclude( $directories )

Searches files and/or directories except in the given path(s).

Searches files and/or directories except in the given path(s).

Parameters

$directories

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# ignoreUnreadableDirs( boolean $yes = true )

Tells Finder to ignore (or not) unreadable directories.

Tells Finder to ignore (or not) unreadable directories.

Parameters

$yes

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# ignoreDots( boolean $yes = true )

Tells Finder to ignore (or not) dot directories. Will remove current directory and parent directory ("." and "..") as well as file starting with ".".

Tells Finder to ignore (or not) dot directories. Will remove current directory and parent directory ("." and "..") as well as file starting with ".".

Parameters

$yes

Returns

KeepItSimple\FileSystem\Finder

Uses

FilesystemIterator::SKIP_DOTS
public KeepItSimple\FileSystem\Finder
# ignoreVCS( boolean $yes = true )

Tells Finder to ignore (or not) VCS files.

Tells Finder to ignore (or not) VCS files.

Parameters

$yes

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# followLinks( boolean $yes = true )

Tells Finder to follow (or not) symbolic links.

Tells Finder to follow (or not) symbolic links.

Parameters

$yes

Returns

KeepItSimple\FileSystem\Finder

Uses

FilesystemIterator::FOLLOW_SYMLINKS
public KeepItSimple\FileSystem\Finder
# sort( callable $callback )

Sorts files and directories from a user defined 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.

Sorts files and directories from a user defined 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

$callback

Returns

KeepItSimple\FileSystem\Finder

Uses

ArrayIterator::uasort()
public KeepItSimple\FileSystem\Finder
# sortByName( )

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

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

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# sortByType( )

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

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

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# sortBySize( )

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

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

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# sortByExtension( )

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

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

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# sortByPath( )

Sorts files and directories by path (without file name). This can be slow as all the matching files and directories must be retrieved for comparison.

Sorts files and directories by path (without file name). This can be slow as all the matching files and directories must be retrieved for comparison.

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# sortByPermission( )

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

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

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# sortByAccessedTime( )

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

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

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# sortByModifiedTime( )

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

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

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# sortByChangedTime( )

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

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

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# filter( callable $callback )

Filters the iterator with a user defined function. The anonymous function receives a SplFileInfo and must return false to remove files.

Filters the iterator with a user defined function. The anonymous function receives a SplFileInfo and must return false to remove files.

Parameters

$callback

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# withName( string $name )

Adds rules that files name must match. You can use patterns regex, globs or simple strings. Example :

$finder->withName('*.php')

will produce same result as

$finder->name('/.php$/')

Adds rules that files name must match. You can use patterns regex, globs or simple strings. Example :

$finder->withName('*.php')

will produce same result as

$finder->name('/.php$/')

Parameters

$name

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# withoutName( $name )

Adds rules that files name must NOT match. You can use patterns regex, globs or simple strings. Example :

$finder->withoutName('*.php')

will produce same result as

$finder->name('/.php$/')

Adds rules that files name must NOT match. You can use patterns regex, globs or simple strings. Example :

$finder->withoutName('*.php')

will produce same result as

$finder->name('/.php$/')

Parameters

$name

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# contains( string $pattern )

Adds rules that files content must match. You can use patterns regex or simple strings. Example :

$finder->contains('Hello World')

will produce same result as

$finder->name('/Hello World/i')

Adds rules that files content must match. You can use patterns regex or simple strings. Example :

$finder->contains('Hello World')

will produce same result as

$finder->name('/Hello World/i')

Parameters

$pattern

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# doesNotContain( $pattern )

Adds rules that files content must NOT match. You can use patterns regex or simple strings. Example :

$finder->doesNotContain('Hello World')

will produce same result as

$finder->name('/Hello World/i')

Adds rules that files content must NOT match. You can use patterns regex or simple strings. Example :

$finder->doesNotContain('Hello World')

will produce same result as

$finder->name('/Hello World/i')

Parameters

$pattern

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# withPath( string $path )

Restrict files and directories by path. You can use patterns regex or simple strings.

Restrict files and directories by path. You can use patterns regex or simple strings.

Parameters

$path

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# withoutPath( string $path )

Exclude files and directories by path. You can use patterns regex or simple strings.

Exclude files and directories by path. You can use patterns regex or simple strings.

Parameters

$path

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# date( string $date )

Adds tests for file dates (last modified). Remove the file if

$current->getCTime() >= strtotime($date)

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

Adds tests for file dates (last modified). Remove the file if

$current->getCTime() >= strtotime($date)

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

Parameters

$date

Returns

KeepItSimple\FileSystem\Finder
public KeepItSimple\FileSystem\Finder
# size( string $size )

Adds tests for file sizes in bytes. Remove the file if

$current->getSize() >= $size

.

Adds tests for file sizes in bytes. Remove the file if

$current->getSize() >= $size

.

Parameters

$size

Returns

KeepItSimple\FileSystem\Finder
public
# depth( integer $depth )

Set the maximum allowed depth.

Set the maximum allowed depth.

Parameters

$depth

Returns


$this
public KeepItSimple\FileSystem\Finder
# merge( KeepItSimple\FileSystem\Finder|Iterator|array $iterator )

Merge an other Finder or Iterator or simple array instance with the current Finder instance.

Merge an other Finder or Iterator or simple array instance with the current Finder instance.

Parameters

$iterator

Returns

KeepItSimple\FileSystem\Finder

Throws

InvalidArgumentException
public Iterator
# getIterator( )

Retrieve an external iterator.

Retrieve an external iterator.

Returns

Iterator
An instance of an object implementing Iterator

Since

5.0.0

Link

http://php.net/manual/en/iteratoraggregate.getiterator.php

Implementation of

IteratorAggregate::getIterator()
public integer
# count( )

Count elements of an object.

Count elements of an object.

Returns

integer
The custom count as an integer.

Since

5.1.0

Link

http://php.net/manual/en/countable.count.php

Implementation of

Countable::count()
Constants summary
integer ONLY_FILES
# 1
integer ONLY_DIRECTORIES
# 2
API documentation generated by ApiGen