| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace League\Flysystem; |
| 6 |
|
| 7 |
use RuntimeException; |
| 8 |
use Throwable; |
| 9 |
|
| 10 |
final class UnableToCopyFile extends RuntimeException implements FilesystemOperationFailed |
| 11 |
{ |
| 12 |
/** |
| 13 |
* @var string |
| 14 |
*/ |
| 15 |
private $source; |
| 16 |
|
| 17 |
/** |
| 18 |
* @var string |
| 19 |
*/ |
| 20 |
private $destination; |
| 21 |
|
| 22 |
public function source(): string |
| 23 |
{ |
| 24 |
return $this->source; |
| 25 |
} |
| 26 |
|
| 27 |
public function destination(): string |
| 28 |
{ |
| 29 |
return $this->destination; |
| 30 |
} |
| 31 |
|
| 32 |
public static function fromLocationTo( |
| 33 |
string $sourcePath, |
| 34 |
string $destinationPath, |
| 35 |
?Throwable $previous = null |
| 36 |
): UnableToCopyFile { |
| 37 |
$e = new static("Unable to copy file from $sourcePath to $destinationPath", 0 , $previous); |
| 38 |
$e->source = $sourcePath; |
| 39 |
$e->destination = $destinationPath; |
| 40 |
|
| 41 |
return $e; |
| 42 |
} |
| 43 |
|
| 44 |
public static function sourceAndDestinationAreTheSame(string $source, string $destination): UnableToCopyFile |
| 45 |
{ |
| 46 |
return UnableToCopyFile::because('Source and destination are the same', $source, $destination); |
| 47 |
} |
| 48 |
|
| 49 |
public static function because(string $reason, string $sourcePath, string $destinationPath): UnableToCopyFile |
| 50 |
{ |
| 51 |
$e = new static("Unable to copy file from $sourcePath to $destinationPath, because $reason"); |
| 52 |
$e->source = $sourcePath; |
| 53 |
$e->destination = $destinationPath; |
| 54 |
|
| 55 |
return $e; |
| 56 |
} |
| 57 |
|
| 58 |
public function operation(): string |
| 59 |
{ |
| 60 |
return FilesystemOperationFailed::OPERATION_COPY; |
| 61 |
} |
| 62 |
} |
| 63 |
|