Mercurial > hg > cmmr2012-drupal-site
comparison core/lib/Drupal/Core/File/FileSystemInterface.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
4 | 4 |
5 /** | 5 /** |
6 * Provides an interface for helpers that operate on files and stream wrappers. | 6 * Provides an interface for helpers that operate on files and stream wrappers. |
7 */ | 7 */ |
8 interface FileSystemInterface { | 8 interface FileSystemInterface { |
9 | |
10 /** | |
11 * Flag for dealing with existing files: Appends number until name is unique. | |
12 */ | |
13 const EXISTS_RENAME = 0; | |
14 | |
15 /** | |
16 * Flag for dealing with existing files: Replace the existing file. | |
17 */ | |
18 const EXISTS_REPLACE = 1; | |
19 | |
20 /** | |
21 * Flag for dealing with existing files: Do nothing and return FALSE. | |
22 */ | |
23 const EXISTS_ERROR = 2; | |
24 | |
25 /** | |
26 * Flag used by ::prepareDirectory() -- create directory if not present. | |
27 */ | |
28 const CREATE_DIRECTORY = 1; | |
29 | |
30 /** | |
31 * Flag used by ::prepareDirectory() -- file permissions may be changed. | |
32 */ | |
33 const MODIFY_PERMISSIONS = 2; | |
9 | 34 |
10 /** | 35 /** |
11 * Moves an uploaded file to a new location. | 36 * Moves an uploaded file to a new location. |
12 * | 37 * |
13 * PHP's move_uploaded_file() does not properly support streams if | 38 * PHP's move_uploaded_file() does not properly support streams if |
235 * Returns TRUE if the string is the name of a validated stream, or FALSE if | 260 * Returns TRUE if the string is the name of a validated stream, or FALSE if |
236 * the scheme does not have a registered handler. | 261 * the scheme does not have a registered handler. |
237 */ | 262 */ |
238 public function validScheme($scheme); | 263 public function validScheme($scheme); |
239 | 264 |
265 /** | |
266 * Copies a file to a new location without invoking the file API. | |
267 * | |
268 * This is a powerful function that in many ways performs like an advanced | |
269 * version of copy(). | |
270 * - Checks if $source and $destination are valid and readable/writable. | |
271 * - If file already exists in $destination either the call will error out, | |
272 * replace the file or rename the file based on the $replace parameter. | |
273 * - If the $source and $destination are equal, the behavior depends on the | |
274 * $replace parameter. FILE_EXISTS_REPLACE will error out. | |
275 * FILE_EXISTS_RENAME will rename the file until the $destination is unique. | |
276 * - Provides a fallback using realpaths if the move fails using stream | |
277 * wrappers. This can occur because PHP's copy() function does not properly | |
278 * support streams if open_basedir is enabled. See | |
279 * https://bugs.php.net/bug.php?id=60456 | |
280 * | |
281 * @param string $source | |
282 * A string specifying the filepath or URI of the source file. | |
283 * @param string $destination | |
284 * A URI containing the destination that $source should be copied to. The | |
285 * URI may be a bare filepath (without a scheme). | |
286 * @param int $replace | |
287 * Replace behavior when the destination file already exists: | |
288 * - FileManagerInterface::FILE_EXISTS_REPLACE - Replace the existing file. | |
289 * - FileManagerInterface::FILE_EXISTS_RENAME - Append _{incrementing | |
290 * number} until the filename is unique. | |
291 * - FileManagerInterface::FILE_EXISTS_ERROR - Throw an exception. | |
292 * | |
293 * @return string | |
294 * The path to the new file. | |
295 * | |
296 * @throws \Drupal\Core\File\Exception\FileException | |
297 * Implementation may throw FileException or its subtype on failure. | |
298 */ | |
299 public function copy($source, $destination, $replace = self::EXISTS_RENAME); | |
300 | |
301 /** | |
302 * Deletes a file without database changes or hook invocations. | |
303 * | |
304 * This function should be used when the file to be deleted does not have an | |
305 * entry recorded in the files table. | |
306 * | |
307 * @param string $path | |
308 * A string containing a file path or (streamwrapper) URI. | |
309 * | |
310 * @throws \Drupal\Core\File\Exception\FileException | |
311 * Implementation may throw FileException or its subtype on failure. | |
312 */ | |
313 public function delete($path); | |
314 | |
315 /** | |
316 * Deletes all files and directories in the specified filepath recursively. | |
317 * | |
318 * If the specified path is a directory then the function is called | |
319 * recursively to process the contents. Once the contents have been removed | |
320 * the directory is also removed. | |
321 * | |
322 * If the specified path is a file then it will be processed with delete() | |
323 * method. | |
324 * | |
325 * Note that this only deletes visible files with write permission. | |
326 * | |
327 * @param string $path | |
328 * A string containing either an URI or a file or directory path. | |
329 * @param callable|null $callback | |
330 * Callback function to run on each file prior to deleting it and on each | |
331 * directory prior to traversing it. For example, can be used to modify | |
332 * permissions. | |
333 * | |
334 * @throws \Drupal\Core\File\Exception\FileException | |
335 * Implementation may throw FileException or its subtype on failure. | |
336 */ | |
337 public function deleteRecursive($path, callable $callback = NULL); | |
338 | |
339 /** | |
340 * Moves a file to a new location without database changes or hook invocation. | |
341 * | |
342 * This is a powerful function that in many ways performs like an advanced | |
343 * version of rename(). | |
344 * - Checks if $source and $destination are valid and readable/writable. | |
345 * - Checks that $source is not equal to $destination; if they are an error | |
346 * is reported. | |
347 * - If file already exists in $destination either the call will error out, | |
348 * replace the file or rename the file based on the $replace parameter. | |
349 * - Works around a PHP bug where rename() does not properly support streams | |
350 * if safe_mode or open_basedir are enabled. | |
351 * | |
352 * @param string $source | |
353 * A string specifying the filepath or URI of the source file. | |
354 * @param string $destination | |
355 * A URI containing the destination that $source should be moved to. The | |
356 * URI may be a bare filepath (without a scheme) and in that case the | |
357 * default scheme (public://) will be used. | |
358 * @param int $replace | |
359 * Replace behavior when the destination file already exists: | |
360 * - FILE_EXISTS_REPLACE - Replace the existing file. | |
361 * - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename | |
362 * is unique. | |
363 * - FILE_EXISTS_ERROR - Do nothing and return FALSE. | |
364 * | |
365 * @return string | |
366 * The path to the new file. | |
367 * | |
368 * @throws \Drupal\Core\File\Exception\FileException | |
369 * Implementation may throw FileException or its subtype on failure. | |
370 * | |
371 * @see https://bugs.php.net/bug.php?id=60456 | |
372 */ | |
373 public function move($source, $destination, $replace = self::EXISTS_RENAME); | |
374 | |
375 /** | |
376 * Saves a file to the specified destination without invoking file API. | |
377 * | |
378 * This function is identical to file_save_data() except the file will not be | |
379 * saved to the {file_managed} table and none of the file_* hooks will be | |
380 * called. | |
381 * | |
382 * @param string $data | |
383 * A string containing the contents of the file. | |
384 * @param string $destination | |
385 * A string containing the destination location. This must be a stream | |
386 * wrapper URI. | |
387 * @param int $replace | |
388 * Replace behavior when the destination file already exists: | |
389 * - FILE_EXISTS_REPLACE - Replace the existing file. | |
390 * - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename | |
391 * is unique. | |
392 * - FILE_EXISTS_ERROR - Do nothing and return FALSE. | |
393 * | |
394 * @return string | |
395 * A string with the path of the resulting file, or FALSE on error. | |
396 * | |
397 * @throws \Drupal\Core\File\Exception\FileException | |
398 * Implementation may throw FileException or its subtype on failure. | |
399 * | |
400 * @see file_save_data() | |
401 */ | |
402 public function saveData($data, $destination, $replace = self::EXISTS_RENAME); | |
403 | |
404 /** | |
405 * Checks that the directory exists and is writable. | |
406 * | |
407 * Directories need to have execute permissions to be considered a directory | |
408 * by FTP servers, etc. | |
409 * | |
410 * @param string $directory | |
411 * A string reference containing the name of a directory path or URI. A | |
412 * trailing slash will be trimmed from a path. | |
413 * @param int $options | |
414 * A bitmask to indicate if the directory should be created if it does | |
415 * not exist (FileSystemInterface::CREATE_DIRECTORY) or made writable if it | |
416 * is read-only (FileSystemInterface::MODIFY_PERMISSIONS). | |
417 * | |
418 * @return bool | |
419 * TRUE if the directory exists (or was created) and is writable. FALSE | |
420 * otherwise. | |
421 */ | |
422 public function prepareDirectory(&$directory, $options = self::MODIFY_PERMISSIONS); | |
423 | |
424 /** | |
425 * Creates a full file path from a directory and filename. | |
426 * | |
427 * If a file with the specified name already exists, an alternative will be | |
428 * used. | |
429 * | |
430 * @param string $basename | |
431 * The filename. | |
432 * @param string $directory | |
433 * The directory or parent URI. | |
434 * | |
435 * @return string | |
436 * File path consisting of $directory and a unique filename based off | |
437 * of $basename. | |
438 * | |
439 * @throws \Drupal\Core\File\Exception\FileException | |
440 * Implementation may throw FileException or its subtype on failure. | |
441 */ | |
442 public function createFilename($basename, $directory); | |
443 | |
444 /** | |
445 * Determines the destination path for a file. | |
446 * | |
447 * @param string $destination | |
448 * The desired final URI or filepath. | |
449 * @param int $replace | |
450 * Replace behavior when the destination file already exists. | |
451 * - FileSystemInterface::EXISTS_REPLACE - Replace the existing file. | |
452 * - FileSystemInterface::EXISTS_RENAME - Append _{incrementing number} | |
453 * until the filename is unique. | |
454 * - FileSystemInterface::EXISTS_ERROR - Do nothing and return FALSE. | |
455 * | |
456 * @return string|bool | |
457 * The destination filepath, or FALSE if the file already exists | |
458 * and FileSystemInterface::EXISTS_ERROR is specified. | |
459 * | |
460 * @throws \Drupal\Core\File\Exception\FileException | |
461 * Implementation may throw FileException or its subtype on failure. | |
462 */ | |
463 public function getDestinationFilename($destination, $replace); | |
464 | |
240 } | 465 } |