|
6 | 6 | use Illuminate\Filesystem\FilesystemAdapter;
|
7 | 7 | use Illuminate\Support\Arr;
|
8 | 8 | use Illuminate\Support\Facades\Storage;
|
| 9 | +use Illuminate\Support\Str; |
| 10 | +use League\Flysystem\Ftp\FtpAdapter; |
9 | 11 | use League\Flysystem\Local\LocalFilesystemAdapter;
|
10 | 12 | use Psr\Http\Message\StreamInterface;
|
11 |
| -use Illuminate\Support\Str; |
12 | 13 | use STS\ZipStream\Contracts\FileContract;
|
13 | 14 | use STS\ZipStream\Exceptions\UnsupportedSourceDiskException;
|
14 | 15 | use STS\ZipStream\OutputStream;
|
@@ -48,6 +49,10 @@ public static function make(string $source, ?string $zipPath = null): static
|
48 | 49 | return new HttpFile($source, $zipPath);
|
49 | 50 | }
|
50 | 51 |
|
| 52 | + if (Str::startsWith($source, "ftp") && filter_var($source, FILTER_VALIDATE_URL)) { |
| 53 | + return new FtpFile($source, $zipPath); |
| 54 | + } |
| 55 | + |
51 | 56 | if (Str::startsWith($source, "/") || preg_match('/^\w:[\/\\\\]/', $source) || file_exists($source)) {
|
52 | 57 | return new LocalFile($source, $zipPath);
|
53 | 58 | }
|
@@ -78,30 +83,42 @@ public static function makeFromDisk($disk, string $source, ?string $zipPath = nu
|
78 | 83 | );
|
79 | 84 | }
|
80 | 85 |
|
| 86 | + if($disk->getAdapter() instanceof FtpAdapter) { |
| 87 | + return FtpFile::makeFromDisk($disk, $source, $zipPath); |
| 88 | + } |
| 89 | + |
81 | 90 | throw new UnsupportedSourceDiskException("Unsupported disk type");
|
82 | 91 | }
|
83 | 92 |
|
84 |
| - public static function makeWriteable(string $source): S3File|LocalFile |
| 93 | + public static function makeWriteable(string $source): static |
85 | 94 | {
|
86 | 95 | if (Str::startsWith($source, "s3://")) {
|
87 | 96 | return new S3File($source);
|
88 | 97 | }
|
89 | 98 |
|
| 99 | + if (Str::startsWith($source, "ftp") && filter_var($source, FILTER_VALIDATE_URL)) { |
| 100 | + return new FtpFile($source); |
| 101 | + } |
| 102 | + |
90 | 103 | return new LocalFile($source);
|
91 | 104 | }
|
92 | 105 |
|
93 |
| - public static function makeWriteableFromDisk($disk, string $source): S3File|LocalFile |
| 106 | + public static function makeWriteableFromDisk($disk, string $source): static |
94 | 107 | {
|
95 |
| - if(!$disk instanceof FilesystemAdapter) { |
| 108 | + if (!$disk instanceof FilesystemAdapter) { |
96 | 109 | $disk = Storage::disk($disk);
|
97 | 110 | }
|
98 | 111 |
|
99 |
| - if($disk instanceof AwsS3V3Adapter) { |
| 112 | + if ($disk instanceof AwsS3V3Adapter) { |
100 | 113 | return S3File::make(
|
101 | 114 | "s3://" . Arr::get($disk->getConfig(), "bucket") . "/" . $disk->path($source)
|
102 | 115 | )->setS3Client($disk->getClient());
|
103 | 116 | }
|
104 | 117 |
|
| 118 | + if ($disk->getAdapter() instanceof FtpAdapter) { |
| 119 | + return FtpFile::makeFromDisk($disk, $source); |
| 120 | + } |
| 121 | + |
105 | 122 | return new LocalFile(
|
106 | 123 | $disk->path($source)
|
107 | 124 | );
|
|
0 commit comments