Issue #2843100 by VladimirAus, quietone, immaculatexavier, yogeshmpawar, gaurav.kapoor, AaronBauman, avpaderno, Munavijayalakshmi, larowlan, smustgrave, Gábor Hojtsy: FileSystemInterface::copy documentation is inaccurate
parent
c9db648a3a
commit
d135a79dc8
|
@ -266,15 +266,29 @@ interface FileSystemInterface {
|
||||||
*
|
*
|
||||||
* This is a powerful function that in many ways performs like an advanced
|
* This is a powerful function that in many ways performs like an advanced
|
||||||
* version of copy().
|
* version of copy().
|
||||||
* - Checks if $source and $destination are valid and readable/writable.
|
* - If $source and $destination are valid and readable/writable, then only
|
||||||
* - If file already exists in $destination either the call will error out,
|
* perform the copy operation.
|
||||||
* replace the file or rename the file based on the $fileExists parameter.
|
* - If $source and $destination are equal then a FileException exception is
|
||||||
* - If the $source and $destination are equal, the behavior depends on the
|
* thrown.
|
||||||
* $fileExists parameter.
|
* - If the $destination file already exists, the behavior depends on the
|
||||||
|
* $fileExists parameter as follows `FileExists::Error` will error out,
|
||||||
|
* `FileExists::Replace` will replace the existing file, and
|
||||||
|
* `FileExists::Rename` will assign a new unique name.
|
||||||
* - Provides a fallback using realpaths if the move fails using stream
|
* - Provides a fallback using realpaths if the move fails using stream
|
||||||
* wrappers. This can occur because PHP's copy() function does not properly
|
* wrappers. This can occur because PHP's copy() function does not properly
|
||||||
* support streams if open_basedir is enabled. See
|
* support streams if open_basedir is enabled.
|
||||||
* https://bugs.php.net/bug.php?id=60456
|
*
|
||||||
|
* Example:
|
||||||
|
* @code
|
||||||
|
* use Drupal\Core\File\FileExists;
|
||||||
|
* use Drupal\Core\File\FileSystemInterface;
|
||||||
|
* ...
|
||||||
|
* $directory = 'public://example-dir';
|
||||||
|
* $file_system = \Drupal::service('file_system');
|
||||||
|
* $file_system->copy($filepath, $directory . '/' . basename($filepath), FileExists::Replace);
|
||||||
|
* @endcode
|
||||||
|
* In this example, file is copied from $filepath and is replaced at the
|
||||||
|
* destination if exists.
|
||||||
*
|
*
|
||||||
* @param string $source
|
* @param string $source
|
||||||
* A string specifying the filepath or URI of the source file.
|
* A string specifying the filepath or URI of the source file.
|
||||||
|
@ -362,6 +376,7 @@ interface FileSystemInterface {
|
||||||
* @throws \ValueError
|
* @throws \ValueError
|
||||||
* Thrown if $fileExists is a legacy int and not a valid value.
|
* Thrown if $fileExists is a legacy int and not a valid value.
|
||||||
*
|
*
|
||||||
|
* @see \Drupal\Core\File\FileSystemInterface::createFilename()
|
||||||
* @see https://bugs.php.net/bug.php?id=60456
|
* @see https://bugs.php.net/bug.php?id=60456
|
||||||
*/
|
*/
|
||||||
public function move($source, $destination, /* FileExists */$fileExists = FileExists::Rename);
|
public function move($source, $destination, /* FileExists */$fileExists = FileExists::Rename);
|
||||||
|
|
Loading…
Reference in New Issue