3 namespace Drupal\Core\File;
6 * Provides an interface for helpers that operate on files and stream wrappers.
8 interface FileSystemInterface {
11 * Moves an uploaded file to a new location.
13 * PHP's move_uploaded_file() does not properly support streams if
14 * open_basedir is enabled, so this function fills that gap.
16 * Compatibility: normal paths and stream wrappers.
18 * @param string $filename
19 * The filename of the uploaded file.
21 * A string containing the destination URI of the file.
24 * TRUE on success, or FALSE on failure.
26 * @see move_uploaded_file()
27 * @see https://www.drupal.org/node/515192
28 * @ingroup php_wrappers
30 public function moveUploadedFile($filename, $uri);
33 * Sets the permissions on a file or directory.
35 * This function will use the file_chmod_directory and
36 * file_chmod_file settings for the default modes for directories
37 * and uploaded/generated files. By default these will give everyone read
38 * access so that users accessing the files with a user account without the
39 * webserver group (e.g. via FTP) can read these files, and give group write
40 * permissions so webserver group members (e.g. a vhost account) can alter
41 * files uploaded and owned by the webserver.
43 * PHP's chmod does not support stream wrappers so we use our wrapper
44 * implementation which interfaces with chmod() by default. Contrib wrappers
45 * may override this behavior in their implementations as needed.
48 * A string containing a URI file, or directory path.
50 * Integer value for the permissions. Consult PHP chmod() documentation for
54 * TRUE for success, FALSE in the event of an error.
56 * @ingroup php_wrappers
58 public function chmod($uri, $mode = NULL);
63 * PHP's unlink() is broken on Windows, as it can fail to remove a file when
64 * it has a read-only flag set.
68 * @param resource $context
69 * Refer to http://php.net/manual/ref.stream.php
72 * Boolean TRUE on success, or FALSE on failure.
75 * @ingroup php_wrappers
77 public function unlink($uri, $context = NULL);
80 * Resolves the absolute filepath of a local URI or filepath.
82 * The use of this method is discouraged, because it does not work for
83 * remote URIs. Except in rare cases, URIs should not be manually resolved.
85 * Only use this function if you know that the stream wrapper in the URI uses
86 * the local file system, and you need to pass an absolute path to a function
87 * that is incompatible with stream URIs.
90 * A stream wrapper URI or a filepath, possibly including one or more
93 * @return string|false
94 * The absolute local filepath (with no symbolic links) or FALSE on failure.
96 * @see \Drupal\Core\StreamWrapper\StreamWrapperInterface::realpath()
97 * @see http://php.net/manual/function.realpath.php
98 * @ingroup php_wrappers
100 public function realpath($uri);
103 * Gets the name of the directory from a given path.
105 * PHP's dirname() does not properly pass streams, so this function fills that
106 * gap. It is backwards compatible with normal paths and will use PHP's
107 * dirname() as a fallback.
109 * Compatibility: normal paths and stream wrappers.
115 * A string containing the directory name.
118 * @see https://www.drupal.org/node/515192
119 * @ingroup php_wrappers
121 public function dirname($uri);
124 * Gets the filename from a given path.
126 * PHP's basename() does not properly support streams or filenames beginning
127 * with a non-US-ASCII character.
129 * @see http://bugs.php.net/bug.php?id=37738
132 * @ingroup php_wrappers
134 public function basename($uri, $suffix = NULL);
137 * Creates a directory, optionally creating missing components in the path to
140 * When PHP's mkdir() creates a directory, the requested mode is affected by
141 * the process's umask. This function overrides the umask and sets the mode
142 * explicitly for all directory components created.
147 * Mode given to created directories. Defaults to the directory mode
148 * configured in the Drupal installation. It must have a leading zero.
149 * @param bool $recursive
150 * Create directories recursively, defaults to FALSE. Cannot work with a
151 * mode which denies writing or execution to the owner of the process.
152 * @param resource $context
153 * Refer to http://php.net/manual/ref.stream.php
156 * Boolean TRUE on success, or FALSE on failure.
159 * @see https://www.drupal.org/node/515192
160 * @ingroup php_wrappers
162 * @todo Update with open_basedir compatible recursion logic from
163 * \Drupal\Component\PhpStorage\FileStorage::ensureDirectory().
165 public function mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL);
168 * Removes a directory.
170 * PHP's rmdir() is broken on Windows, as it can fail to remove a directory
171 * when it has a read-only flag set.
175 * @param resource $context
176 * Refer to http://php.net/manual/ref.stream.php
179 * Boolean TRUE on success, or FALSE on failure.
182 * @ingroup php_wrappers
184 public function rmdir($uri, $context = NULL);
187 * Creates a file with a unique filename in the specified directory.
189 * PHP's tempnam() does not return a URI like we want. This function will
190 * return a URI if given a URI, or it will return a filepath if given a
193 * Compatibility: normal paths and stream wrappers.
195 * @param string $directory
196 * The directory where the temporary filename will be created.
197 * @param string $prefix
198 * The prefix of the generated temporary filename.
199 * Note: Windows uses only the first three characters of prefix.
201 * @return string|bool
202 * The new temporary filename, or FALSE on failure.
205 * @see https://www.drupal.org/node/515192
206 * @ingroup php_wrappers
208 public function tempnam($directory, $prefix);
211 * Returns the scheme of a URI (e.g. a stream).
214 * A stream, referenced as "scheme://target" or "data:target".
216 * @return string|bool
217 * A string containing the name of the scheme, or FALSE if none. For
218 * example, the URI "public://example.txt" would return "public".
220 * @see file_uri_target()
222 public function uriScheme($uri);
225 * Checks that the scheme of a stream URI is valid.
227 * Confirms that there is a registered stream handler for the provided scheme
228 * and that it is callable. This is useful if you want to confirm a valid
229 * scheme without creating a new instance of the registered handler.
231 * @param string $scheme
232 * A URI scheme, a stream is referenced as "scheme://target".
235 * Returns TRUE if the string is the name of a validated stream, or FALSE if
236 * the scheme does not have a registered handler.
238 public function validScheme($scheme);