Skip to content

Commit

Permalink
feature: remove UploadedFile, use webman-tech/polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
krissss committed Sep 17, 2022
1 parent 362fe2b commit 558dd0c
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 487 deletions.
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ composer require league/flysystem:~1.1
composer require league/flysystem
```

3. 安装 `symfony/mime`(可选),用于校验文件真实的 mime-type

```bash
composer require symfony/mime
```

## 使用

所有 API 同 laravel,以下仅对有些特殊的操作做说明
Expand All @@ -61,26 +55,35 @@ php webman storage:link
> 同 Laravel,可以支持自定义建立多个对外的路劲软链
### 文件上传
### Request 文件上传

原 Laravel 下通过 `$request()->file()` 之后的快捷文件操作,使用 `UploadedFile::wrapper($request->file())` 来代替,举例如下:
原 Laravel 下通过 `$request()->file()` 之后的快捷文件操作,需要使用 [`webman-tech/polyfill`](https://github.com/webman-tech/polyfill) 来支持

> 注意:此处操作非完全兼容,因为 Laravel 的 UploadedFile 是基于 Symfony 的 UploadedFile 的,而我们的是基于 webman 的 UploadFile 的
安装

```bash
composer require webman-tech/polyfill illuminate/http
```

使用

```bash
<?php

namespace app\controller;

use WebmanTech\LaravelFilesystem\Http\UploadedFile;
use support\Request;
use WebmanTech\Polyfill\LaravelRequest;
use WebmanTech\Polyfill\LaravelUploadedFile;

class UserAvatarController
{
public function update(Request $request)
{
$path = UploadedFile::wrapper($request->file('avatar'))->store('avatars');

$path = LaravelRequest::wrapper($request)->file('file')->store('avatars');
// 或者
$path = LaravelUploadedFile::wrapper($request->file('avatar'))->store('avatars');

return response($path);
}
}
Expand Down
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
"php": ">=7.4"
},
"require-dev": {
"workerman/webman-framework": "^1.4",
"league/flysystem": "^1.1",
"illuminate/filesystem": "^8.83",
"webman/console": "^1.2",
"symfony/mime": "^5.4",
"iidestiny/flysystem-oss": "~2",
"illuminate/filesystem": "^8.83",
"league/flysystem": "^1.1",
"overtrue/flysystem-cos": "~3",
"overtrue/flysystem-qiniu": "~1",
"overtrue/flysystem-cos": "~3"
"webman/console": "^1.2",
"workerman/webman-framework": "^1.4"
},
"autoload": {
"psr-4": {
Expand All @@ -26,7 +25,9 @@
},
"suggest": {
"illuminate/filesystem:~8 and league/flysystem:~1.1": "flysystem v1 for laravel v8",
"illuminate/filesystem:~9 and league/flysystem:~3.0": "flysystem v3 for laravel v9",
"symfony/mime": "UploadedFile need to guess real extension"
"illuminate/filesystem:~9 and league/flysystem:~3.0": "flysystem v3 for laravel v9"
},
"config": {
"sort-packages": true
}
}
7 changes: 6 additions & 1 deletion src/Facades/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@
*/
class File
{
public static function instance(): Filesystem
{
return Container::get(Filesystem::class);
}

public static function __callStatic($name, $arguments)
{
return Container::get(Filesystem::class)->{$name}(...$arguments);
return static::instance()->{$name}(...$arguments);
}
}
16 changes: 10 additions & 6 deletions src/Facades/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

namespace WebmanTech\LaravelFilesystem\Facades;

use WebmanTech\LaravelFilesystem\FilesystemManager;
use support\Container;
use WebmanTech\LaravelFilesystem\FilesystemManager;

/**
* @method static \Illuminate\Contracts\Filesystem\Filesystem assertExists(string|array $path)
* @method static \Illuminate\Contracts\Filesystem\Filesystem assertDirectoryEmpty(string $path)
* @method static \Illuminate\Contracts\Filesystem\Filesystem assertMissing(string|array $path)
* @method static \Illuminate\Contracts\Filesystem\Filesystem cloud()
* @method static \Illuminate\Contracts\Filesystem\Filesystem build(string|array $root)
Expand All @@ -28,7 +27,7 @@
* @method static bool missing(string $path)
* @method static bool move(string $from, string $to)
* @method static bool prepend(string $path, string $data)
* @method static bool put(string $path, \Webman\Http\UploadFile|\Webman\File|string|resource $contents, mixed $options = [])
* @method static bool put(string $path, \Psr\Http\Message\StreamInterface|\Illuminate\Http\File|\Illuminate\Http\UploadedFile|string|resource $contents, mixed $options = [])
* @method static bool setVisibility(string $path, string $visibility)
* @method static bool writeStream(string $path, resource $resource, array $options = [])
* @method static int lastModified(string $path)
Expand All @@ -40,8 +39,8 @@
* @method static string temporaryUrl(string $path, \DateTimeInterface $expiration, array $options = [])
* @method static string url(string $path)
* @method static string|false mimeType(string $path)
* @method static string|false putFile(string $path, \Webman\Http\UploadFile|\Webman\File|string $file, mixed $options = [])
* @method static string|false putFileAs(string $path, \Webman\Http\UploadFile|\Webman\File|string $file, string $name, mixed $options = [])
* @method static string|false putFile(string $path, \Illuminate\Http\File|\Illuminate\Http\UploadedFile|string $file, mixed $options = [])
* @method static string|false putFileAs(string $path, \Illuminate\Http\File|\Illuminate\Http\UploadedFile|string $file, string $name, mixed $options = [])
* @method static void macro(string $name, object|callable $macro)
* @method static void buildTemporaryUrlsUsing(\Closure $callback)
*
Expand All @@ -50,8 +49,13 @@
*/
class Storage
{
public static function instance(): FilesystemManager
{
return Container::get(FilesystemManager::class);
}

public static function __callStatic($name, $arguments)
{
return Container::get(FilesystemManager::class)->{$name}(...$arguments);
return static::instance()->{$name}(...$arguments);
}
}
2 changes: 1 addition & 1 deletion src/FilesystemManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FilesystemManager extends LaravelFilesystemManager

public function __construct()
{
$this->filesystemConfig = config('plugin.kriss.webman-filesystem.filesystems', []);
$this->filesystemConfig = config('plugin.webman-tech.laravel-filesystem.filesystems', []);
$this->customCreators = $this->filesystemConfig['extends'] ?? [];
parent::__construct(null);
}
Expand Down
59 changes: 0 additions & 59 deletions src/Http/FileHelpers.php

This file was deleted.

66 changes: 0 additions & 66 deletions src/Http/SymfonyFileTrait.php

This file was deleted.

Loading

0 comments on commit 558dd0c

Please sign in to comment.