class PathCollection extends ArrayObject (View source)

A PathLocator collection class

Constants

STD_PROP_LIST

Properties of the object have their normal functionality when accessed as list (var_dump, foreach, etc.).

ARRAY_AS_PROPS

Entries can be accessed as properties (read and write).

Methods

__construct(array $paths = array())

PathCollection constructor.

boolean
__isset(mixed $key)

Returns whether the requested key exists

void|mixed
__set(mixed $key, mixed $value)

Sets the value at the specified key to value

void|mixed
__unset(mixed $key)

Unsets the value at the specified key

mixed
__get(mixed $key)

Returns the value at the specified key by reference

void
append(mixed $value)

Appends the value

void
asort()

Sort the entries by value

int
count()

Get the number of public properties in the ArrayObject

array
exchangeArray(array|ArrayObject $data)

Exchange the array for another one.

array
getArrayCopy()

Creates a copy of the ArrayObject.

int
getFlags()

Gets the behavior flags.

getIterator()

Create a new iterator from an ArrayObject instance

string
getIteratorClass()

Gets the iterator classname for the ArrayObject.

void
ksort()

Sort the entries by key

void
natcasesort()

Sort an array using a case insensitive "natural order" algorithm

void
natsort()

Sort entries using a "natural order" algorithm

bool
offsetExists(mixed $key)

Returns whether the requested key exists

mixed
offsetGet(mixed $key)

Returns the value at the specified key

void
offsetSet(mixed $key, mixed $value)

Sets the value at the specified key to value

void
offsetUnset(mixed $key)

Unsets the value at the specified key

string
serialize()

Serialize an ArrayObject

void
setFlags(int $flags)

Sets the behavior flags

void
setIteratorClass(string $class)

Sets the iterator classname for the ArrayObject

void
uasort(callable $function)

Sort the entries with a user-defined comparison function and maintain key association

void
uksort(callable $function)

Sort the entries by keys using a user-defined comparison function

void
unserialize(string $data)

Unserialize an ArrayObject

addPaths(mixed $paths)

Batch add paths to bag.

addPath(mixed $path, string $key = null)

Add one path to bag.

removePath(string $key)

Using key to remove a path from bag.

array
getPaths()

Get all paths with key from bag.

getPath(string $key, string $default = null)

Using key to get a path.

getAllChildren(boolean $recursive = false)

Get all files and folders as an iterator.

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

Find one file from all paths.

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

Find all files from paths.

getFiles(boolean $recursive = false)

Get file iterator of all paths

getFolders(boolean $recursive = false)

Get folder iterator of all paths

setPrefix(string $prefix)

Set prefix to all paths.

appendAll(string $appended)

Append a new path to all paths.

prependAll(string $prepended)

Prepend a new path to all paths.

array
toArray(bool $reindex = false)

Convert paths bag to array, and every path to string.

boolean
isSubdir(PathLocator $path)

Is this path a subdir of another path in bag?

Details

at line line 41
__construct(array $paths = array())

PathCollection constructor.

Parameters

array $paths The PathLocator array.

in ArrayObject at line line 72
boolean __isset(mixed $key)

Returns whether the requested key exists

Parameters

mixed $key

Return Value

boolean

Exceptions

InvalidArgumentException

in ArrayObject at line line 96
void|mixed __set(mixed $key, mixed $value)

Sets the value at the specified key to value

Parameters

mixed $key
mixed $value

Return Value

void|mixed

Exceptions

InvalidArgumentException

void|mixed __unset(mixed $key)

Unsets the value at the specified key

Parameters

mixed $key

Return Value

void|mixed

Exceptions

InvalidArgumentException

mixed __get(mixed $key)

Returns the value at the specified key by reference

Parameters

mixed $key

Return Value

mixed

Exceptions

InvalidArgumentException

void append(mixed $value)

Appends the value

Parameters

mixed $value

Return Value

void

void asort()

Sort the entries by value

Return Value

void

int count()

Get the number of public properties in the ArrayObject

Return Value

int

array exchangeArray(array|ArrayObject $data)

Exchange the array for another one.

Parameters

array|ArrayObject $data

Return Value

array

Exceptions

InvalidArgumentException

array getArrayCopy()

Creates a copy of the ArrayObject.

Return Value

array

int getFlags()

Gets the behavior flags.

Return Value

int

Iterator getIterator()

Create a new iterator from an ArrayObject instance

Return Value

Iterator

string getIteratorClass()

Gets the iterator classname for the ArrayObject.

Return Value

string

void ksort()

Sort the entries by key

Return Value

void

void natcasesort()

Sort an array using a case insensitive "natural order" algorithm

Return Value

void

void natsort()

Sort entries using a "natural order" algorithm

Return Value

void

bool offsetExists(mixed $key)

Returns whether the requested key exists

Parameters

mixed $key

Return Value

bool

mixed offsetGet(mixed $key)

Returns the value at the specified key

Parameters

mixed $key

Return Value

mixed

void offsetSet(mixed $key, mixed $value)

Sets the value at the specified key to value

Parameters

mixed $key
mixed $value

Return Value

void

void offsetUnset(mixed $key)

Unsets the value at the specified key

Parameters

mixed $key

Return Value

void

string serialize()

Serialize an ArrayObject

Return Value

string

void setFlags(int $flags)

Sets the behavior flags

Parameters

int $flags

Return Value

void

void setIteratorClass(string $class)

Sets the iterator classname for the ArrayObject

Parameters

string $class

Return Value

void

Exceptions

InvalidArgumentException

void uasort(callable $function)

Sort the entries with a user-defined comparison function and maintain key association

Parameters

callable $function

Return Value

void

void uksort(callable $function)

Sort the entries by keys using a user-defined comparison function

Parameters

callable $function

Return Value

void

void unserialize(string $data)

Unserialize an ArrayObject

Parameters

string $data

Return Value

void

at line line 55
PathCollection addPaths(mixed $paths)

Batch add paths to bag.

Parameters

mixed $paths Paths to add to path bag, string will be converted to PathLocator object.

Return Value

PathCollection Return this object to support chaining.

at line line 81
PathCollection addPath(mixed $path, string $key = null)

Add one path to bag.

Parameters

mixed $path The path your want to store in bag, have to be a string or PathLocator object.
string $key Path key, useful when you want to remove a path.

Return Value

PathCollection Return this object to support chaining.

Exceptions

InvalidArgumentException

at line line 121
PathCollection removePath(string $key)

Using key to remove a path from bag.

Parameters

string $key The key of path you want to remove.

Return Value

PathCollection Return this object to support chaining.

at line line 135
array getPaths()

Get all paths with key from bag.

Return Value

array An array includes all path objects.

at line line 152
PathLocator getPath(string $key, string $default = null)

Using key to get a path.

Parameters

string $key The key of path you want to get.
string $default If path not exists, return this default path. Default value can be PathLocator object string or null. String will auto wrapped by object, if is null, just return null.

Return Value

PathLocator The path which you want.

at line line 214
AppendIterator getAllChildren(boolean $recursive = false)

Get all files and folders as an iterator.

Parameters

boolean $recursive True to support recrusive.

Return Value

AppendIterator An OutterIterator contains all paths' iterator.

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

Find one file from all paths.

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 272
AppendIterator find(mixed $condition, boolean $recursive = false)

Find all files from paths.

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

AppendIterator Finded files or paths iterator.

at line line 289
AppendIterator getFiles(boolean $recursive = false)

Get file iterator of all paths

Parameters

boolean $recursive True to resursive.

Return Value

AppendIterator Iterator only include files.

at line line 306
AppendIterator getFolders(boolean $recursive = false)

Get folder iterator of all paths

Parameters

boolean $recursive True to resursive.

Return Value

AppendIterator Iterator only include dirs.

at line line 325
PathCollection setPrefix(string $prefix)

Set prefix to all paths.

Parameters

string $prefix The prefix path you want to prepend when path convert to string.

Return Value

PathCollection Return this object to support chaining.

at line line 344
PathCollection appendAll(string $appended)

Append a new path to all paths.

Parameters

string $appended Path to append.

Return Value

PathCollection Return this object to support chaining.

at line line 363
PathCollection prependAll(string $prepended)

Prepend a new path to all paths.

Parameters

string $prepended Path to prepend.

Return Value

PathCollection Return this object to support chaining.

at line line 382
array toArray(bool $reindex = false)

Convert paths bag to array, and every path to string.

Parameters

bool $reindex

Return Value

array Raw paths.

at line line 412
boolean isSubdir(PathLocator $path)

Is this path a subdir of another path in bag?

When running recursive scan dir, we have to avoid to re scan same dir.

Parameters

PathLocator $path The path to detect is subdir or not.

Return Value

boolean Is subdir or not.