class PathLocator implements PathLocatorInterface, IteratorAggregate (View source)

A Path locator class

Methods

__construct(string $path)

Constructor to handle path.

redirect(string $path)

Replace with a new path.

getIterator(boolean $recursive = false)

Get file iterator of current dir.

getFolders(boolean $recursive = false)

Get folder iterator of current dir.

getFiles(boolean $recursive = false)

Get file iterator of current dir

findOne(mixed $condition, boolean $recursive = false)

Find one file and return.

find(mixed $condition, boolean $recursive = false)

Find all files which matches condition.

findByCallback(Closure $callback, boolean $recursive = false)

Using a closure function to filter file.

boolean
isDir()

Detect is current path a dir?

boolean
isFile()

Detect is current path a file?

boolean
exists()

Detect is current path exists?

setPrefix(string $prefix = '')

Set a prefix, when this object convert to string, prefix will auto add to the front of path.

child(string $name)

Get a child path of given name.

parent(boolean $condition = null)

Get a parent path of given condition.

append(string $path)

Append a new path before current path.

prepend(string $path)

Append a new path before current path.

boolean
isSubdirOf(string $parent)

Is this path subdir of given path?

string
__toString()

Convert this object to string.

Details

at line line 51
__construct(string $path)

Constructor to handle path.

Parameters

string $path Path to parse.

at line line 65
PathLocator redirect(string $path)

Replace with a new path.

Parameters

string $path Path to parse.

Return Value

PathLocator Return this object to support chaining.

at line line 79
FilesystemIterator|RecursiveIteratorIterator getIterator(boolean $recursive = false)

Get file iterator of current dir.

Parameters

boolean $recursive True to resursive.

Return Value

FilesystemIterator|RecursiveIteratorIterator File & dir iterator.

at line line 92
CallbackFilterIterator getFolders(boolean $recursive = false)

Get folder iterator of current dir.

Parameters

boolean $recursive True to resursive.

Return Value

CallbackFilterIterator Iterator only include dirs.

at line line 104
CallbackFilterIterator getFiles(boolean $recursive = false)

Get file iterator of current dir

Parameters

boolean $recursive True to resursive.

Return Value

CallbackFilterIterator Iterator only include files.

at line line 126
SplFileInfo findOne(mixed $condition, boolean $recursive = false)

Find one file and return.

Parameters

mixed $condition Finding condition, that can be a string, a regex or a callback function. Callback example: function($current, $key, $iterator) { return @preg_match('^Foo', $current->getFilename()) && ! $iterator->isDot(); }
boolean $recursive True to resursive.

Return Value

SplFileInfo Finded file info object.

at line line 148
CallbackFilterIterator find(mixed $condition, boolean $recursive = false)

Find all files which matches condition.

Parameters

mixed $condition Finding condition, that can be a string, a regex or a callback function. Callback example: function($current, $key, $iterator) { return @preg_match('^Foo', $current->getFilename()) && ! $iterator->isDot(); }
boolean $recursive True to resursive.

Return Value

CallbackFilterIterator Finded files or paths iterator.

at line line 164
CallbackFilterIterator findByCallback(Closure $callback, boolean $recursive = false)

Using a closure function to filter file.

Parameters

Closure $callback A callback function to filter file.
boolean $recursive True to recursive.

Return Value

CallbackFilterIterator Filtered file or path iteator.

See also

http://www.php.net/manual/en/class.callbackfilteriterator.php

at line line 271
boolean isDir()

Detect is current path a dir?

Return Value

boolean True if is a dir.

at line line 283
boolean isFile()

Detect is current path a file?

Return Value

boolean True if is a file.

at line line 295
boolean exists()

Detect is current path exists?

Return Value

boolean True if exists.

at line line 310
PathLocator setPrefix(string $prefix = '')

Set a prefix, when this object convert to string, prefix will auto add to the front of path.

Parameters

string $prefix Prefix string to set.

Return Value

PathLocator Return this object to support chaining.

at line line 326
PathLocator child(string $name)

Get a child path of given name.

Parameters

string $name Child name.

Return Value

PathLocator Return this object to support chaining.

at line line 344
PathLocator parent(boolean $condition = null)

Get a parent path of given condition.

Parameters

boolean $condition Parent condition.

Return Value

PathLocator Return this object to support chaining.

at line line 397
PathLocator append(string $path)

Append a new path before current path.

Parameters

string $path Path to append.

Return Value

PathLocator Return this object to support chaining.

at line line 420
PathLocator prepend(string $path)

Append a new path before current path.

Parameters

string $path Path to append.

Return Value

PathLocator Return this object to support chaining.

at line line 443
boolean isSubdirOf(string $parent)

Is this path subdir of given path?

Parameters

string $parent Given path to detect.

Return Value

boolean Is subdir or not.

at line line 471
string __toString()

Convert this object to string.

Return Value

string Path name.