class filesystem extends filesystem

deprecated 3.2.0-dev (To be removed 4.0.0) use \phpbb\filesystem\filesystem instead

Properties

protected array $chmod_info Store some information about file ownership for phpBB's chmod function from filesystem
protected string|bool $working_directory Stores current working directory from filesystem
protected Filesystem $symfony_filesystem Symfony's Filesystem component from filesystem

Methods

__construct()

Constructor

chgrp(string|array|Traversable $files, string $group, bool $recursive = false)

Change owner group of files/directories

chmod(string|array|Traversable $files, int $perms = null, bool $recursive = false, bool $force_chmod_link = false)

Global function for chmodding directories and files for internal use

chown(string|array|Traversable $files, string $user, bool $recursive = false)

Change owner group of files/directories

string
clean_path(string $path)

Eliminates useless . and .

copy(string $origin_file, string $target_file, bool $override = false)

Copies a file.

dump_file(string $filename, string $content)

Atomically dumps content into a file.

bool
exists(string|array|Traversable $files)

Checks the existence of files or directories.

bool
is_absolute_path(string $path)

Checks if a path is absolute or not

bool
is_readable(string|array|Traversable $files, bool $recursive = false)

Checks if files/directories are readable

bool
is_writable(string|array|Traversable $files, bool $recursive = false)

Test if a file/directory is writable

string
make_path_relative(string $end_path, string $start_path)

Given an existing path, convert it to a path relative to a given starting path

mirror(string $origin_dir, string $target_dir, Traversable $iterator = null, array $options = array())

Mirrors a directory to another.

mkdir(string|array|Traversable $dirs, int $mode = 0777)

Creates a directory recursively.

phpbb_chmod($files, int $perms = null, bool $recursive = false, bool $force_chmod_link = false)

Global function for chmodding directories and files for internal use

string
realpath(string $path)

A wrapper for PHP's realpath

remove(string|array|Traversable $files)

Removes files or directories.

rename(string $origin, string $target, bool $overwrite = false)

Renames a file or a directory.

symlink(string $origin_dir, string $target_dir, bool $copy_on_windows = false)

Creates a symbolic link or copy a directory.

touch(string|array|Traversable $files, int $time = null, int $access_time = null)

Sets access and modification time of file.

bool
phpbb_is_writable(string $file)

phpBB's implementation of is_writable

bool|string
phpbb_own_realpath(string $path)

Try to resolve real path when PHP's realpath failes to do so

to_iterator(string|array|Traversable $files)

Convert file(s) to \Traversable object

string|array|bool
resolve_path(string $path, string $prefix = '', bool $absolute = false, bool $return_array = false)

Try to resolve symlinks in path

Details

in filesystem at line 47
__construct()

Constructor

in filesystem at line 57
chgrp(string|array|Traversable $files, string $group, bool $recursive = false)

Change owner group of files/directories

Parameters

string|array|Traversable $files The file(s)/directorie(s) to change group
string $group The group that should own the files/directories
bool $recursive If the group should be changed recursively

Exceptions

filesystem_exception the filename which triggered the error can be retrieved by filesystem_exception::get_filename()

in filesystem at line 77
chmod(string|array|Traversable $files, int $perms = null, bool $recursive = false, bool $force_chmod_link = false)

Global function for chmodding directories and files for internal use

The function accepts filesystem_interface::CHMOD_ flags in the permission argument or the user can specify octal values (or any integer if it makes sense). All directories will have an execution bit appended, if the user group (owner, group or other) has any bit specified.

Parameters

string|array|Traversable $files The file/directory to be chmodded
int $perms Permissions to set
bool $recursive If the permissions should be changed recursively
bool $force_chmod_link Try to apply permissions to symlinks as well

Exceptions

filesystem_exception the filename which triggered the error can be retrieved by filesystem_exception::get_filename()

in filesystem at line 143
chown(string|array|Traversable $files, string $user, bool $recursive = false)

Change owner group of files/directories

Parameters

string|array|Traversable $files The file(s)/directorie(s) to change group
string $user The owner user name
bool $recursive Whether change the owner recursively or not

Exceptions

filesystem_exception the filename which triggered the error can be retrieved by filesystem_exception::get_filename()

in filesystem at line 163
string clean_path(string $path)

Eliminates useless . and .

. components from specified path.

Parameters

string $path Path to clean

Return Value

string Cleaned path

in filesystem at line 190
copy(string $origin_file, string $target_file, bool $override = false)

Copies a file.

This method only copies the file if the origin file is newer than the target file.

By default, if the target already exists, it is not overridden.

Parameters

string $origin_file The original filename
string $target_file The target filename
bool $override Whether to override an existing file or not

Exceptions

filesystem_exception When the file cannot be copied

in filesystem at line 205
dump_file(string $filename, string $content)

Atomically dumps content into a file.

Parameters

string $filename The file to be written to.
string $content The data to write into the file.

Exceptions

filesystem_exception When the file cannot be written

in filesystem at line 220
bool exists(string|array|Traversable $files)

Checks the existence of files or directories.

Parameters

string|array|Traversable $files files/directories to check

Return Value

bool Returns true if all files/directories exist, false otherwise

in filesystem at line 228
bool is_absolute_path(string $path)

Checks if a path is absolute or not

Parameters

string $path Path to check

Return Value

bool true if the path is absolute, false otherwise

in filesystem at line 236
bool is_readable(string|array|Traversable $files, bool $recursive = false)

Checks if files/directories are readable

Parameters

string|array|Traversable $files files/directories to check
bool $recursive Whether or not directories should be checked recursively

Return Value

bool True when the files/directories are readable, otherwise false.

in filesystem at line 260
bool is_writable(string|array|Traversable $files, bool $recursive = false)

Test if a file/directory is writable

Parameters

string|array|Traversable $files files/directories to perform write test on
bool $recursive Whether or not directories should be checked recursively

Return Value

bool True when the files/directories are writable, otherwise false.

in filesystem at line 306
string make_path_relative(string $end_path, string $start_path)

Given an existing path, convert it to a path relative to a given starting path

Parameters

string $end_path Absolute path of target
string $start_path Absolute path where traversal begins

Return Value

string Path of target relative to starting path

in filesystem at line 314
mirror(string $origin_dir, string $target_dir, Traversable $iterator = null, array $options = array())

Mirrors a directory to another.

Parameters

string $origin_dir The origin directory
string $target_dir The target directory
Traversable $iterator A Traversable instance
array $options An array of boolean options Valid options are: - $options['override'] Whether to override an existing file on copy or not (see copy()) - $options['copy_on_windows'] Whether to copy files instead of links on Windows (see symlink()) - $options['delete'] Whether to delete files that are not in the source directory (defaults to false)

Exceptions

filesystem_exception When the file cannot be copied. The filename which triggered the error can be retrieved by filesystem_exception::get_filename()

in filesystem at line 332
mkdir(string|array|Traversable $dirs, int $mode = 0777)

Creates a directory recursively.

Parameters

string|array|Traversable $dirs The directory path
int $mode The directory mode

Exceptions

filesystem_exception On any directory creation failure The filename which triggered the error can be retrieved by filesystem_exception::get_filename()

in filesystem at line 350
phpbb_chmod($files, int $perms = null, bool $recursive = false, bool $force_chmod_link = false)

Global function for chmodding directories and files for internal use

This function determines owner and group whom the file belongs to and user and group of PHP and then set safest possible file permissions. The function determines owner and group from common.php file and sets the same to the provided file. The function uses bit fields to build the permissions. The function sets the appropriate execute bit on directories.

Supported constants representing bit fields are:

filesystem_interface::CHMOD_ALL - all permissions (7) filesystem_interface::CHMOD_READ - read permission (4) filesystem_interface::CHMOD_WRITE - write permission (2) filesystem_interface::CHMOD_EXECUTE - execute permission (1)

NOTE: The function uses POSIX extension and fileowner()/filegroup() functions. If any of them is disabled, this function tries to build proper permissions, by calling is_readable() and is_writable() functions.

Parameters

$files
int $perms Permissions to set
bool $recursive If the permissions should be changed recursively
bool $force_chmod_link Try to apply permissions to symlinks as well

Exceptions

filesystem_exception the filename which triggered the error can be retrieved by filesystem_exception::get_filename()

in filesystem at line 487
string realpath(string $path)

A wrapper for PHP's realpath

Try to resolve realpath when PHP's realpath is not available, or known to be buggy.

Parameters

string $path Path to resolve

Return Value

string Resolved path

in filesystem at line 515
remove(string|array|Traversable $files)

Removes files or directories.

Parameters

string|array|Traversable $files A filename, an array of files, or a \Traversable instance to remove

Exceptions

filesystem_exception When removal fails. The filename which triggered the error can be retrieved by filesystem_exception::get_filename()

in filesystem at line 535
rename(string $origin, string $target, bool $overwrite = false)

Renames a file or a directory.

Parameters

string $origin The origin filename or directory
string $target The new filename or directory
bool $overwrite Whether to overwrite the target if it already exists

Exceptions

filesystem_exception When target file or directory already exists, or origin cannot be renamed.

Creates a symbolic link or copy a directory.

Parameters

string $origin_dir The origin directory path
string $target_dir The symbolic link name
bool $copy_on_windows Whether to copy files if on Windows

Exceptions

filesystem_exception When symlink fails

in filesystem at line 568
touch(string|array|Traversable $files, int $time = null, int $access_time = null)

Sets access and modification time of file.

Parameters

string|array|Traversable $files A filename, an array of files, or a \Traversable instance to create
int $time The touch time as a Unix timestamp
int $access_time The access time as a Unix timestamp

Exceptions

filesystem_exception When touch fails

in filesystem at line 594
protected bool phpbb_is_writable(string $file)

phpBB's implementation of is_writable

Parameters

string $file file/directory to check if writable

Return Value

bool true if the given path is writable

in filesystem at line 645
protected bool|string phpbb_own_realpath(string $path)

Try to resolve real path when PHP's realpath failes to do so

Parameters

string $path

Return Value

bool|string

in filesystem at line 754
protected Traversable to_iterator(string|array|Traversable $files)

Convert file(s) to \Traversable object

This is the same function as Symfony's toIterator, but that is private so we cannot use it.

Parameters

string|array|Traversable $files filename/list of filenames

Return Value

Traversable

in filesystem at line 775
protected string|array|bool resolve_path(string $path, string $prefix = '', bool $absolute = false, bool $return_array = false)

Try to resolve symlinks in path

Parameters

string $path The path to resolve
string $prefix The path prefix (on windows the drive letter)
bool $absolute Whether or not the path is absolute
bool $return_array Whether or not to return path parts

Return Value

string|array|bool returns the resolved path or an array of parts of the path if $return_array is true or false if path cannot be resolved