Page MenuHomePhorge

final class FileList
libphutil Technical Documentation (Filesystem)

A list of files, primarily useful for parsing command line arguments. This class makes it easier to deal with user-specified lists of files and directories used by command line tools.

$list = new FileList(array_slice($argv, 1));
foreach ($some_files as $file) {
  if ($list->contains($file)) {
    do_something_to_this($file);
  }
}

This sort of construction will allow the user to type "src" in order to indicate 'all relevant files underneath "src/"'.

Tasks

Creating a File List

  • public function __construct($paths) — Build a new FileList from an array of paths, e.g. from $argv.

Testing File Lists

  • public function contains($path, $allow_parent_directory) — Determine if a path is one of the paths in the list. Note that an empty file list is considered to contain every file.
  • public function isEmpty() — Check if the file list is empty -- that is, it contains no files.

Other Methods

Methods

public function __get($name)
Inherited

This method is not documented.
Parameters
$name
Return
wild

public function __set($name, $value)
Inherited

This method is not documented.
Parameters
$name
$value
Return
wild

public function current()
Inherited

This method is not documented.
Return
wild

public function key()
Inherited

This method is not documented.
Return
wild

public function next()
Inherited

This method is not documented.
Return
wild

public function rewind()
Inherited

This method is not documented.
Return
wild

public function valid()
Inherited

This method is not documented.
Return
wild

private function throwOnAttemptedIteration()
Inherited

This method is not documented.
Return
wild

public function getPhobjectClassConstant($key, $byte_limit)
Inherited

Phobject

Read the value of a class constant.

This is the same as just typing self::CONSTANTNAME, but throws a more useful message if the constant is not defined and allows the constant to be limited to a maximum length.

Parameters
string$keyName of the constant.
int|null$byte_limitMaximum number of bytes permitted in the value.
Return
stringValue of the constant.

public function __construct($paths)

Build a new FileList from an array of paths, e.g. from $argv.

Parameters
list$pathsList of relative or absolute file paths.
Return
this//Implicit.//

public function contains($path, $allow_parent_directory)

Determine if a path is one of the paths in the list. Note that an empty file list is considered to contain every file.

Parameters
string$pathRelative or absolute system file path.
bool$allow_parent_directoryIf true, consider the path to be contained in the list if the list contains a parent directory. If false, require that the path be part of the list explicitly.
Return
boolIf true, the file is in the list.

public function isEmpty()

Check if the file list is empty -- that is, it contains no files.

Return
boolIf true, the list is empty.