annotate core/lib/Drupal/Core/File/FileSystemInterface.php @ 13:5fb285c0d0e3

Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've been lucky to get away with this so far, as we don't support self-registration which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5 was vulnerable to.
author Chris Cannam
date Mon, 23 Apr 2018 09:33:26 +0100
parents 4c8ae668cc8c
children af1871eacc83
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Core\File;
Chris@0 4
Chris@0 5 /**
Chris@0 6 * Provides an interface for helpers that operate on files and stream wrappers.
Chris@0 7 */
Chris@0 8 interface FileSystemInterface {
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Moves an uploaded file to a new location.
Chris@0 12 *
Chris@0 13 * PHP's move_uploaded_file() does not properly support streams if
Chris@0 14 * open_basedir is enabled, so this function fills that gap.
Chris@0 15 *
Chris@0 16 * Compatibility: normal paths and stream wrappers.
Chris@0 17 *
Chris@0 18 * @param string $filename
Chris@0 19 * The filename of the uploaded file.
Chris@0 20 * @param string $uri
Chris@0 21 * A string containing the destination URI of the file.
Chris@0 22 *
Chris@0 23 * @return bool
Chris@0 24 * TRUE on success, or FALSE on failure.
Chris@0 25 *
Chris@0 26 * @see move_uploaded_file()
Chris@0 27 * @see https://www.drupal.org/node/515192
Chris@0 28 * @ingroup php_wrappers
Chris@0 29 */
Chris@0 30 public function moveUploadedFile($filename, $uri);
Chris@0 31
Chris@0 32 /**
Chris@0 33 * Sets the permissions on a file or directory.
Chris@0 34 *
Chris@0 35 * This function will use the file_chmod_directory and
Chris@0 36 * file_chmod_file settings for the default modes for directories
Chris@0 37 * and uploaded/generated files. By default these will give everyone read
Chris@0 38 * access so that users accessing the files with a user account without the
Chris@0 39 * webserver group (e.g. via FTP) can read these files, and give group write
Chris@0 40 * permissions so webserver group members (e.g. a vhost account) can alter
Chris@0 41 * files uploaded and owned by the webserver.
Chris@0 42 *
Chris@0 43 * PHP's chmod does not support stream wrappers so we use our wrapper
Chris@0 44 * implementation which interfaces with chmod() by default. Contrib wrappers
Chris@0 45 * may override this behavior in their implementations as needed.
Chris@0 46 *
Chris@0 47 * @param string $uri
Chris@0 48 * A string containing a URI file, or directory path.
Chris@0 49 * @param int $mode
Chris@0 50 * Integer value for the permissions. Consult PHP chmod() documentation for
Chris@0 51 * more information.
Chris@0 52 *
Chris@0 53 * @return bool
Chris@0 54 * TRUE for success, FALSE in the event of an error.
Chris@0 55 *
Chris@0 56 * @ingroup php_wrappers
Chris@0 57 */
Chris@0 58 public function chmod($uri, $mode = NULL);
Chris@0 59
Chris@0 60 /**
Chris@0 61 * Deletes a file.
Chris@0 62 *
Chris@0 63 * PHP's unlink() is broken on Windows, as it can fail to remove a file when
Chris@0 64 * it has a read-only flag set.
Chris@0 65 *
Chris@0 66 * @param string $uri
Chris@0 67 * A URI or pathname.
Chris@0 68 * @param resource $context
Chris@0 69 * Refer to http://php.net/manual/ref.stream.php
Chris@0 70 *
Chris@0 71 * @return bool
Chris@0 72 * Boolean TRUE on success, or FALSE on failure.
Chris@0 73 *
Chris@0 74 * @see unlink()
Chris@0 75 * @ingroup php_wrappers
Chris@0 76 */
Chris@0 77 public function unlink($uri, $context = NULL);
Chris@0 78
Chris@0 79 /**
Chris@0 80 * Resolves the absolute filepath of a local URI or filepath.
Chris@0 81 *
Chris@0 82 * The use of this method is discouraged, because it does not work for
Chris@0 83 * remote URIs. Except in rare cases, URIs should not be manually resolved.
Chris@0 84 *
Chris@0 85 * Only use this function if you know that the stream wrapper in the URI uses
Chris@0 86 * the local file system, and you need to pass an absolute path to a function
Chris@0 87 * that is incompatible with stream URIs.
Chris@0 88 *
Chris@0 89 * @param string $uri
Chris@0 90 * A stream wrapper URI or a filepath, possibly including one or more
Chris@0 91 * symbolic links.
Chris@0 92 *
Chris@0 93 * @return string|false
Chris@0 94 * The absolute local filepath (with no symbolic links) or FALSE on failure.
Chris@0 95 *
Chris@0 96 * @see \Drupal\Core\StreamWrapper\StreamWrapperInterface::realpath()
Chris@0 97 * @see http://php.net/manual/function.realpath.php
Chris@0 98 * @ingroup php_wrappers
Chris@0 99 */
Chris@0 100 public function realpath($uri);
Chris@0 101
Chris@0 102 /**
Chris@0 103 * Gets the name of the directory from a given path.
Chris@0 104 *
Chris@0 105 * PHP's dirname() does not properly pass streams, so this function fills that
Chris@0 106 * gap. It is backwards compatible with normal paths and will use PHP's
Chris@0 107 * dirname() as a fallback.
Chris@0 108 *
Chris@0 109 * Compatibility: normal paths and stream wrappers.
Chris@0 110 *
Chris@0 111 * @param string $uri
Chris@0 112 * A URI or path.
Chris@0 113 *
Chris@0 114 * @return string
Chris@0 115 * A string containing the directory name.
Chris@0 116 *
Chris@0 117 * @see dirname()
Chris@0 118 * @see https://www.drupal.org/node/515192
Chris@0 119 * @ingroup php_wrappers
Chris@0 120 */
Chris@0 121 public function dirname($uri);
Chris@0 122
Chris@0 123 /**
Chris@0 124 * Gets the filename from a given path.
Chris@0 125 *
Chris@0 126 * PHP's basename() does not properly support streams or filenames beginning
Chris@0 127 * with a non-US-ASCII character.
Chris@0 128 *
Chris@0 129 * @see http://bugs.php.net/bug.php?id=37738
Chris@0 130 * @see basename()
Chris@0 131 *
Chris@0 132 * @ingroup php_wrappers
Chris@0 133 */
Chris@0 134 public function basename($uri, $suffix = NULL);
Chris@0 135
Chris@0 136 /**
Chris@0 137 * Creates a directory, optionally creating missing components in the path to
Chris@0 138 * the directory.
Chris@0 139 *
Chris@0 140 * When PHP's mkdir() creates a directory, the requested mode is affected by
Chris@0 141 * the process's umask. This function overrides the umask and sets the mode
Chris@0 142 * explicitly for all directory components created.
Chris@0 143 *
Chris@0 144 * @param string $uri
Chris@0 145 * A URI or pathname.
Chris@0 146 * @param int $mode
Chris@0 147 * Mode given to created directories. Defaults to the directory mode
Chris@0 148 * configured in the Drupal installation. It must have a leading zero.
Chris@0 149 * @param bool $recursive
Chris@0 150 * Create directories recursively, defaults to FALSE. Cannot work with a
Chris@0 151 * mode which denies writing or execution to the owner of the process.
Chris@0 152 * @param resource $context
Chris@0 153 * Refer to http://php.net/manual/ref.stream.php
Chris@0 154 *
Chris@0 155 * @return bool
Chris@0 156 * Boolean TRUE on success, or FALSE on failure.
Chris@0 157 *
Chris@0 158 * @see mkdir()
Chris@0 159 * @see https://www.drupal.org/node/515192
Chris@0 160 * @ingroup php_wrappers
Chris@0 161 *
Chris@0 162 * @todo Update with open_basedir compatible recursion logic from
Chris@0 163 * \Drupal\Component\PhpStorage\FileStorage::ensureDirectory().
Chris@0 164 */
Chris@0 165 public function mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL);
Chris@0 166
Chris@0 167 /**
Chris@0 168 * Removes a directory.
Chris@0 169 *
Chris@0 170 * PHP's rmdir() is broken on Windows, as it can fail to remove a directory
Chris@0 171 * when it has a read-only flag set.
Chris@0 172 *
Chris@0 173 * @param string $uri
Chris@0 174 * A URI or pathname.
Chris@0 175 * @param resource $context
Chris@0 176 * Refer to http://php.net/manual/ref.stream.php
Chris@0 177 *
Chris@0 178 * @return bool
Chris@0 179 * Boolean TRUE on success, or FALSE on failure.
Chris@0 180 *
Chris@0 181 * @see rmdir()
Chris@0 182 * @ingroup php_wrappers
Chris@0 183 */
Chris@0 184 public function rmdir($uri, $context = NULL);
Chris@0 185
Chris@0 186 /**
Chris@0 187 * Creates a file with a unique filename in the specified directory.
Chris@0 188 *
Chris@0 189 * PHP's tempnam() does not return a URI like we want. This function will
Chris@0 190 * return a URI if given a URI, or it will return a filepath if given a
Chris@0 191 * filepath.
Chris@0 192 *
Chris@0 193 * Compatibility: normal paths and stream wrappers.
Chris@0 194 *
Chris@0 195 * @param string $directory
Chris@0 196 * The directory where the temporary filename will be created.
Chris@0 197 * @param string $prefix
Chris@0 198 * The prefix of the generated temporary filename.
Chris@0 199 * Note: Windows uses only the first three characters of prefix.
Chris@0 200 *
Chris@0 201 * @return string|bool
Chris@0 202 * The new temporary filename, or FALSE on failure.
Chris@0 203 *
Chris@0 204 * @see tempnam()
Chris@0 205 * @see https://www.drupal.org/node/515192
Chris@0 206 * @ingroup php_wrappers
Chris@0 207 */
Chris@0 208 public function tempnam($directory, $prefix);
Chris@0 209
Chris@0 210 /**
Chris@0 211 * Returns the scheme of a URI (e.g. a stream).
Chris@0 212 *
Chris@0 213 * @param string $uri
Chris@0 214 * A stream, referenced as "scheme://target" or "data:target".
Chris@0 215 *
Chris@0 216 * @return string|bool
Chris@0 217 * A string containing the name of the scheme, or FALSE if none. For
Chris@0 218 * example, the URI "public://example.txt" would return "public".
Chris@0 219 *
Chris@0 220 * @see file_uri_target()
Chris@0 221 */
Chris@0 222 public function uriScheme($uri);
Chris@0 223
Chris@0 224 /**
Chris@0 225 * Checks that the scheme of a stream URI is valid.
Chris@0 226 *
Chris@0 227 * Confirms that there is a registered stream handler for the provided scheme
Chris@0 228 * and that it is callable. This is useful if you want to confirm a valid
Chris@0 229 * scheme without creating a new instance of the registered handler.
Chris@0 230 *
Chris@0 231 * @param string $scheme
Chris@0 232 * A URI scheme, a stream is referenced as "scheme://target".
Chris@0 233 *
Chris@0 234 * @return bool
Chris@0 235 * Returns TRUE if the string is the name of a validated stream, or FALSE if
Chris@0 236 * the scheme does not have a registered handler.
Chris@0 237 */
Chris@0 238 public function validScheme($scheme);
Chris@0 239
Chris@0 240 }