12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace Modules\Common\Support\Upload;
- use Catch\Exceptions\FailedException;
- use Illuminate\Http\UploadedFile;
- use Modules\Common\Support\Upload\Uses\LocalUpload;
- class Uploader
- {
- protected string $driver = 'local';
-
- protected string $path = '';
-
- public function upload(UploadedFile $file): array
- {
- try {
- return $this->getDriver()->setUploadedFile($file)->upload();
- } catch (\Exception $exception) {
- throw new FailedException($exception->getMessage());
- }
- }
-
- public function getDriver()
- {
- $drivers = $this->getDrivers();
- $driver = $drivers[$this->driver] ?? null;
- if (! $driver) {
- throw new FailedException('Upload Driver Not Found');
- }
- return app($driver);
- }
-
- public function setDriver(string $driver): static
- {
- $this->driver = $driver;
- return $this;
- }
-
- public function getDrivers(): array
- {
- return [
- 'local' => LocalUpload::class,
- 'HuaweiOBS' => HuaweiOBSUpload::class,
- ];
- }
- }
|