Drupal 8  8.0.2
FileSystem Class Reference
Inheritance diagram for FileSystem:

Public Member Functions

 __construct (StreamWrapperManagerInterface $stream_wrapper_manager, Settings $settings, LoggerInterface $logger)
 
 moveUploadedFile ($filename, $uri)
 
 chmod ($uri, $mode=NULL)
 
 unlink ($uri, $context=NULL)
 
 realpath ($uri)
 
 dirname ($uri)
 
 basename ($uri, $suffix=NULL)
 
 mkdir ($uri, $mode=NULL, $recursive=FALSE, $context=NULL)
 
 rmdir ($uri, $context=NULL)
 
 tempnam ($directory, $prefix)
 
 uriScheme ($uri)
 
 validScheme ($scheme)
 

Data Fields

const CHMOD_DIRECTORY = 0775
 
const CHMOD_FILE = 0664
 

Protected Member Functions

 mkdirCall ($uri, $mode, $recursive, $context)
 

Protected Attributes

 $settings
 
 $logger
 
 $streamWrapperManager
 

Detailed Description

Provides helpers to operate on files and stream wrappers.

Constructor & Destructor Documentation

__construct ( StreamWrapperManagerInterface  $stream_wrapper_manager,
Settings  $settings,
LoggerInterface  $logger 
)

Constructs a new FileSystem.

Parameters
\Drupal\Core\StreamWrapper\StreamWrapperManagerInterface$stream_wrapper_managerThe stream wrapper manager.
\Drupal\Core\Site\Settings$settingsThe site settings.
\Psr\Log\LoggerInterface$loggerThe file logger channel.

References Drupal\logger().

Here is the call graph for this function:

Member Function Documentation

basename (   $uri,
  $suffix = NULL 
)

{Gets the filename from a given path.PHP's basename() does not properly support streams or filenames beginning with a non-US-ASCII character.

See Also
http://bugs.php.net/bug.php?id=37738
basename()
}

Implements FileSystemInterface.

chmod (   $uri,
  $mode = NULL 
)

{Sets the permissions on a file or directory.This function will use the file_chmod_directory and file_chmod_file settings for the default modes for directories and uploaded/generated files. By default these will give everyone read access so that users accessing the files with a user account without the webserver group (e.g. via FTP) can read these files, and give group write permissions so webserver group members (e.g. a vhost account) can alter files uploaded and owned by the webserver.PHP's chmod does not support stream wrappers so we use our wrapper implementation which interfaces with chmod() by default. Contrib wrappers may override this behavior in their implementations as needed.

Parameters
string$uriA string containing a URI file, or directory path.
int$modeInteger value for the permissions. Consult PHP chmod() documentation for more information.
Returns
bool TRUE for success, FALSE in the event of an error.
}

Implements FileSystemInterface.

References Drupal\logger().

Referenced by FileSystem\mkdir(), FileSystem\rmdir(), and FileSystem\unlink().

Here is the call graph for this function:

Here is the caller graph for this function:

dirname (   $uri)

{Gets the name of the directory from a given path.PHP's dirname() does not properly pass streams, so this function fills that gap. It is backwards compatible with normal paths and will use PHP's dirname() as a fallback.Compatibility: normal paths and stream wrappers.

Parameters
string$uriA URI or path.
Returns
string A string containing the directory name.
See Also
dirname()
https://www.drupal.org/node/515192
}

Implements FileSystemInterface.

References FileSystem\uriScheme(), and FileSystem\validScheme().

Here is the call graph for this function:

mkdir (   $uri,
  $mode = NULL,
  $recursive = FALSE,
  $context = NULL 
)

{Creates a directory, optionally creating missing components in the path to the directory.When PHP's mkdir() creates a directory, the requested mode is affected by the process's umask. This function overrides the umask and sets the mode explicitly for all directory components created.

Parameters
string$uriA URI or pathname.
int$modeMode given to created directories. Defaults to the directory mode configured in the Drupal installation. It must have a leading zero.
bool$recursiveCreate directories recursively, defaults to FALSE. Cannot work with a mode which denies writing or execution to the owner of the process.
resource$contextRefer to http://php.net/manual/ref.stream.php
Returns
bool Boolean TRUE on success, or FALSE on failure.
See Also
mkdir()
https://www.drupal.org/node/515192
Todo:
Update with open_basedir compatible recursion logic from ::ensureDirectory().
}

Implements FileSystemInterface.

References FileSystem\chmod(), FileSystem\mkdirCall(), and FileSystem\uriScheme().

Referenced by FileSystem\mkdirCall().

Here is the call graph for this function:

Here is the caller graph for this function:

mkdirCall (   $uri,
  $mode,
  $recursive,
  $context 
)
protected

Helper function. Ensures we don't pass a NULL as a context resource to mkdir().

See Also
self::mkdir()

References FileSystem\mkdir().

Referenced by FileSystem\mkdir().

Here is the call graph for this function:

Here is the caller graph for this function:

moveUploadedFile (   $filename,
  $uri 
)

{Moves an uploaded file to a new location.PHP's move_uploaded_file() does not properly support streams if open_basedir is enabled, so this function fills that gap.Compatibility: normal paths and stream wrappers.

Parameters
string$filenameThe filename of the uploaded file.
string$uriA string containing the destination URI of the file.
Returns
bool TRUE on success, or FALSE on failure.
See Also
move_uploaded_file()
https://www.drupal.org/node/515192
}

Implements FileSystemInterface.

References FileSystem\realpath().

Here is the call graph for this function:

realpath (   $uri)

{Resolves the absolute filepath of a local URI or filepath.The use of this method is discouraged, because it does not work for remote URIs. Except in rare cases, URIs should not be manually resolved.Only use this function if you know that the stream wrapper in the URI uses the local file system, and you need to pass an absolute path to a function that is incompatible with stream URIs.

Parameters
string$uriA stream wrapper URI or a filepath, possibly including one or more symbolic links.
Returns
string|false The absolute local filepath (with no symbolic links) or FALSE on failure.
See Also
::realpath()
http://php.net/manual/function.realpath.php
}

Implements FileSystemInterface.

Referenced by FileSystem\moveUploadedFile().

Here is the caller graph for this function:

rmdir (   $uri,
  $context = NULL 
)

{Removes a directory.PHP's rmdir() is broken on Windows, as it can fail to remove a directory when it has a read-only flag set.

Parameters
string$uriA URI or pathname.
resource$contextRefer to http://php.net/manual/ref.stream.php
Returns
bool Boolean TRUE on success, or FALSE on failure.
See Also
rmdir()
}

Implements FileSystemInterface.

References FileSystem\chmod(), FileSystem\uriScheme(), and FileSystem\validScheme().

Here is the call graph for this function:

tempnam (   $directory,
  $prefix 
)

{Creates a file with a unique filename in the specified directory.PHP's tempnam() does not return a URI like we want. This function will return a URI if given a URI, or it will return a filepath if given a filepath.Compatibility: normal paths and stream wrappers.

Parameters
string$directoryThe directory where the temporary filename will be created.
string$prefixThe prefix of the generated temporary filename. Note: Windows uses only the first three characters of prefix.
Returns
string|bool The new temporary filename, or FALSE on failure.
See Also
tempnam()
https://www.drupal.org/node/515192
}

Implements FileSystemInterface.

References FileSystem\uriScheme(), and FileSystem\validScheme().

Here is the call graph for this function:

unlink (   $uri,
  $context = NULL 
)

{Deletes a file.PHP's unlink() is broken on Windows, as it can fail to remove a file when it has a read-only flag set.

Parameters
string$uriA URI or pathname.
resource$contextRefer to http://php.net/manual/ref.stream.php
Returns
bool Boolean TRUE on success, or FALSE on failure.
See Also
unlink()
}

Implements FileSystemInterface.

References FileSystem\chmod(), FileSystem\uriScheme(), and FileSystem\validScheme().

Here is the call graph for this function:

uriScheme (   $uri)

{Returns the scheme of a URI (e.g. a stream).

Parameters
string$uriA stream, referenced as "scheme://target" or "data:target".
Returns
string|bool A string containing the name of the scheme, or FALSE if none. For example, the URI "public://example.txt" would return "public".
See Also
file_uri_target()
}

Implements FileSystemInterface.

Referenced by FileSystem\dirname(), FileSystem\mkdir(), FileSystem\rmdir(), FileSystem\tempnam(), and FileSystem\unlink().

Here is the caller graph for this function:

validScheme (   $scheme)

{Checks that the scheme of a stream URI is valid.Confirms that there is a registered stream handler for the provided scheme and that it is callable. This is useful if you want to confirm a valid scheme without creating a new instance of the registered handler.

Parameters
string$schemeA URI scheme, a stream is referenced as "scheme://target".
Returns
bool Returns TRUE if the string is the name of a validated stream, or FALSE if the scheme does not have a registered handler.
}

Implements FileSystemInterface.

Referenced by FileSystem\dirname(), FileSystem\rmdir(), FileSystem\tempnam(), and FileSystem\unlink().

Here is the caller graph for this function:

Field Documentation

const CHMOD_DIRECTORY = 0775

Default mode for new directories. See self::chmod().

Referenced by FileSystemTest\testChmodDir().

const CHMOD_FILE = 0664

The documentation for this class was generated from the following file: