Class Symfony\Component\Filesystem\Filesystem

InheritanceSymfony\Component\Filesystem\Filesystem

Provides basic utility to manipulate the file system.

Public Methods

Hide inherited methods

MethodDescriptionDefined By
chgrp() Change the group of an array of files or directories. Symfony\Component\Filesystem\Filesystem
chmod() Change mode for an array of files or directories. Symfony\Component\Filesystem\Filesystem
chown() Change the owner of an array of files or directories. Symfony\Component\Filesystem\Filesystem
copy() Copies a file. Symfony\Component\Filesystem\Filesystem
dumpFile() Atomically dumps content into a file. Symfony\Component\Filesystem\Filesystem
exists() Checks the existence of files or directories. Symfony\Component\Filesystem\Filesystem
isAbsolutePath() Returns whether the file path is an absolute path. Symfony\Component\Filesystem\Filesystem
makePathRelative() Given an existing path, convert it to a path relative to a given starting path. Symfony\Component\Filesystem\Filesystem
mirror() Mirrors a directory to another. Symfony\Component\Filesystem\Filesystem
mkdir() Creates a directory recursively. Symfony\Component\Filesystem\Filesystem
remove() Removes files or directories. Symfony\Component\Filesystem\Filesystem
rename() Renames a file or a directory. Symfony\Component\Filesystem\Filesystem
symlink() Creates a symbolic link or copy a directory. Symfony\Component\Filesystem\Filesystem
tempnam() Creates a temporary file with support for custom stream wrappers. Symfony\Component\Filesystem\Filesystem
touch() Sets access and modification time of file. Symfony\Component\Filesystem\Filesystem

Method Details

chgrp() public method

Change the group of an array of files or directories.

public void chgrp ( $files, $group, $recursive false )
$files string|array|Traversable

A filename, an array of files, or a \Traversable instance to change group

$group string

The group name

$recursive bool

Whether change the group recursively or not

throws Symfony\Component\Filesystem\Exception\IOException

When the change fail

chmod() public method

Change mode for an array of files or directories.

public void chmod ( $files, $mode, $umask 0, $recursive false )
$files string|array|Traversable

A filename, an array of files, or a \Traversable instance to change mode

$mode int

The new mode (octal)

$umask int

The mode mask (octal)

$recursive bool

Whether change the mod recursively or not

throws Symfony\Component\Filesystem\Exception\IOException

When the change fail

chown() public method

Change the owner of an array of files or directories.

public void chown ( $files, $user, $recursive false )
$files string|array|Traversable

A filename, an array of files, or a \Traversable instance to change owner

$user string

The new owner user name

$recursive bool

Whether change the owner recursively or not

throws Symfony\Component\Filesystem\Exception\IOException

When the change fail

copy() public method

Copies a file.

If the target file is older than the origin file, it's always overwritten. If the target file is newer, it is overwritten only when the $overwriteNewerFiles option is set to true.

public void copy ( $originFile, $targetFile, $overwriteNewerFiles false )
$originFile string

The original filename

$targetFile string

The target filename

$overwriteNewerFiles bool

If true, target files newer than origin files are overwritten

throws Symfony\Component\Filesystem\Exception\FileNotFoundException

When originFile doesn't exist

throws Symfony\Component\Filesystem\Exception\IOException

When copy fails

dumpFile() public method

Atomically dumps content into a file.

public void dumpFile ( $filename, $content )
$filename string

The file to be written to

$content string

The data to write into the file

throws Symfony\Component\Filesystem\Exception\IOException

If the file cannot be written to.

exists() public method

Checks the existence of files or directories.

public bool exists ( $files )
$files string|array|Traversable

A filename, an array of files, or a \Traversable instance to check

return bool

True if the file exists, false otherwise

isAbsolutePath() public method

Returns whether the file path is an absolute path.

public bool isAbsolutePath ( $file )
$file string

A file path

makePathRelative() public method

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

public string makePathRelative ( $endPath, $startPath )
$endPath string

Absolute path of target

$startPath string

Absolute path where traversal begins

return string

Path of target relative to starting path

mirror() public method

Mirrors a directory to another.

public void mirror ( $originDir, $targetDir, Traversable $iterator null, $options = [] )
$originDir string

The origin directory

$targetDir string

The target directory

$iterator Traversable

A Traversable instance

$options array

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)
throws Symfony\Component\Filesystem\Exception\IOException

When file type is unknown

mkdir() public method

Creates a directory recursively.

public void mkdir ( $dirs, $mode 511 )
$dirs string|array|Traversable

The directory path

$mode int

The directory mode

throws Symfony\Component\Filesystem\Exception\IOException

On any directory creation failure

remove() public method

Removes files or directories.

public void remove ( $files )
$files string|array|Traversable

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

throws Symfony\Component\Filesystem\Exception\IOException

When removal fails

rename() public method

Renames a file or a directory.

public void rename ( $origin, $target, $overwrite false )
$origin string

The origin filename or directory

$target string

The new filename or directory

$overwrite bool

Whether to overwrite the target if it already exists

throws Symfony\Component\Filesystem\Exception\IOException

When origin cannot be renamed

symlink() public method

Creates a symbolic link or copy a directory.

public void symlink ( $originDir, $targetDir, $copyOnWindows false )
$originDir string

The origin directory path

$targetDir string

The symbolic link name

$copyOnWindows bool

Whether to copy files if on Windows

throws Symfony\Component\Filesystem\Exception\IOException

When symlink fails

tempnam() public method

Creates a temporary file with support for custom stream wrappers.

public string tempnam ( $dir, $prefix )
$dir string

The directory where the temporary filename will be created

$prefix string

The prefix of the generated temporary filename

                  Note: Windows uses only the first three characters of prefix
return string

The new temporary filename (with path), or throw an exception on failure

touch() public method

Sets access and modification time of file.

public void touch ( $files, $time null, $atime null )
$files string|array|Traversable

A filename, an array of files, or a \Traversable instance to create

$time int

The touch time as a Unix timestamp

$atime int

The access time as a Unix timestamp

throws Symfony\Component\Filesystem\Exception\IOException

When touch fails